将下列数据(上映年份 电影数量 0 2017 12 1 2019 10 2 2016 8 3 2018 7 4 2015 7 5 2022 6 6 2012 6 7 2013 5 8 2009 4 9 2007 4 10 2010 4 11 2011 3 12 2021 3 13 2002 3 14 2014 2 15 2005 2 16 2004 2 17 2003 2 18 2001 2 19 1996 1 20 1993 1 21 1994 1 22 2008 1 23 1997 1 24 1999 1 25 2006 1 26 1982 1)以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="最大值")] ) ) ) c.render_notebook()在这段代码的基础下,以折线图是升序的格式输出
时间: 2023-06-14 17:04:57 浏览: 187
电影数据.html
可以在代码中添加一行 `.set_series_opts(is_sort=True)`,来将折线图按照 x 轴的升序排列。修改后的代码如下:
```
from pyecharts.charts import Line
import pyecharts.options as opts
Year = {'上映年份': ['2017', '2019', '2016', '2018', '2015', '2022', '2012', '2013', '2009', '2007', '2010', '2011', '2021', '2002', '2014', '2005', '2004', '2003', '2001', '1996', '1993', '1994', '2008', '1997', '1999', '2006', '1982'], '电影数量': [12, 10, 8, 7, 7, 6, 6, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1]}
c = (
Line(init_opts=opts.InitOpts(theme="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()
```
执行后会得到一个升序排列的折线图。
阅读全文