from pyecharts.charts import Line import pyecharts.options as opts c = ( Line(init_opts=opts.InitOpts(theme = ThemeType.CHALK)) .set_global_opts( title_opts=opts.TitleOpts(title="电影数量"), xaxis_opts=opts.AxisOpts(type_="category"), yaxis_opts=opts.AxisOpts( type_="value", axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), ), ) .add_xaxis(xaxis_data=Year['上映年份']) .add_yaxis( series_name="电影数量", y_axis=Year['电影数量'], symbol="emptyCircle", is_symbol_show=True, label_opts=opts.LabelOpts(is_show=False), itemstyle_opts=opts.ItemStyleOpts( color="red"), markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_="max",name="最大值")] ) ) .set_series_opts(is_sort=True) ) c.render_notebook() 请修改一下代码,将折线图中x轴中上映年份以升序的形式排列在图中呈现出来
时间: 2023-06-13 12:07:32 浏览: 202
可以通过对传入的 `xaxis_data` 进行排序来实现 x 轴的升序排列。修改后的代码如下:
```python
from pyecharts.charts import Line
import pyecharts.options as opts
c = (
Line(init_opts=opts.InitOpts(theme=ThemeType.CHALK))
.set_global_opts(
title_opts=opts.TitleOpts(title="电影数量"),
xaxis_opts=opts.AxisOpts(type_="category"),
yaxis_opts=opts.AxisOpts(
type_="value",
axistick_opts=opts.AxisTickOpts(is_show=True),
splitline_opts=opts.SplitLineOpts(is_show=True),
),
)
.add_xaxis(xaxis_data=Year['上映年份'].sort_values())
.add_yaxis(
series_name="电影数量",
y_axis=Year['电影数量'],
symbol="emptyCircle",
is_symbol_show=True,
label_opts=opts.LabelOpts(is_show=False),
itemstyle_opts=opts.ItemStyleOpts(color="red"),
markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max", name="最大值")])
)
.set_series_opts(is_sort=True)
)
c.render_notebook()
```
其中,用 `sort_values()` 方法对 `Year['上映年份']` 进行排序。
阅读全文