Notebook
Different Notebook environments have their own different rendering requirements, pyecharts has done adaptation processing at the bottom, but because we cannot import pyecharts
know which Notebook environment the user is using, we need to declare the environment type at the top when using it .
Jupyter Notebook
Jupyter Notebook directly calls render_notebook
to render charts anytime and anywhere, the default is Jupter-Notebook
.
Jupyter Lab
There are two points to note when rendering in Jupyter Lab
- The notebook type is declared at the top, and must be declared before introducing modules such as pyecharts.charts
from pyecharts.globals import CurrentConfig, NotebookType CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB
- In the first rendering, the call
load_javascript()
will preload the basic JavaScript file into the Notebook. If other graphics cannot be rendered later, please try to call it again, becauseload_javascript
only the most basic js references will be pre-loaded. Themes, maps and other js files need to be loaded again on demand . load_javascript()
Andrender_notebook()
methods need to call in a different cell, which is inline Notebook mechanism, in fact, we are essentially returned with_html_
,_javascript_
class objects. The notebook will automatically call these methods.
Nteract
There are two points to note when rendering with Nteract
- The notebook type is declared at the top, and must be declared before introducing modules such as pyecharts.charts
from pyecharts.globals import CurrentConfig, NotebookType CurrentConfig.NOTEBOOK_TYPE = NotebookType.NTERACT
nteract calls the render_notebook
method to render
from pyecharts.globals import CurrentConfig, NotebookType
CurrentConfig.NOTEBOOK_TYPE = NotebookType.NTERACT
import pyecharts.options as opts
from pyecharts.charts import Bar, Line
bar = (
Bar()
.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
.add_yaxis("商家B", [15, 6, 45, 20, 35, 66])
.set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))
)
bar.render_notebook()
Zeppelin
Zeppelin needs attention when rendering
- The notebook type is declared at the top, and must be declared before introducing modules such as pyecharts.charts
from pyecharts.globals import CurrentConfig, NotebookType CurrentConfig.NOTEBOOK_TYPE = NotebookType.ZEPPELIN
Zeppelin calls the render_notebook
method to render
%python
from pyecharts.globals import CurrentConfig, NotebookType
CurrentConfig.NOTEBOOK_TYPE = NotebookType.ZEPPELIN
import pyecharts.options as opts
from pyecharts.charts import Bar
bar = (
Bar()
.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
.add_yaxis("商家B", [15, 6, 45, 20, 35, 66])
.set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))
)
bar.render_notebook()