如何做柱状图和折线图的组合图 怎么做折线图( 二 )

<"gdpPercap">/1000).astype(float) #Get gdpPercap as Tousand /人均GDP以千元单位显示df<"Year"> = df<"year">.astype(str) #Convert year as int into stringdisplay(df)Get_Two_Bar_One_Line(df,"南非")#Get a dataset of a dedicated countrydf = px.data.gapminder().query("country == <'Thailand'>") #'Japan','Germany','Italy','Canada','Spain','Thailand','Argentina'df<"life"> = df<"lifeExp">.astype(int)df<"pop-Million"> = (df<"pop">/1000000).astype(int) #Get pop 100W /人口数量以百万单位来显示df<"gdpPercap-Thousand"> = (df<"gdpPercap">/1000).astype(float) #Get gdpPercap as Tousand /人均GDP以千元单位显示df<"Year"> = df<"year">.astype(str) #Convert year as int into stringdisplay(df)#<'#0d0887','#46039f', '#7201a8', '#9c179e', '#bd3786', '#d8576b', '#ed7953', '#fb9f3a', '#fdca26', '#f0f921'>def Get_Two_Bar_One_Line(X,Y):fig = go.Figure()# Create figure with secondary y-axisfig = make_subplots(specs=<<{"secondary_y": True}>>)# Add tracesfig_bar_one = go.Bar(name="人口数量", x=X<"Year">, y=X<"pop-Million">,marker_color='#44cef6')fig_bar_two = go.Bar(name="平均寿命", x=X<"Year">, y=X<"life">, marker_color='#9c179e')fig_line_one = go.Scatter(name="人均GDP",x=X<"Year">, y=X<"gdpPercap-Thousand">,line=dict(color='red', width=3, dash='dash'))#define the positionsfig.add_trace(fig_bar_one,secondary_y=False)fig.add_trace(fig_bar_two,secondary_y=False)fig.add_trace(fig_line_one,secondary_y=True)# Add figure titlefig.update_layout(title_text=Y)# Set x-axis titlefig.update_xaxes(title_text="1952年到2007年期间国家整体情况变化")# Set y-axes titlesfig.update_yaxes(title_text="<b>primary</b>--人口数量百万和平均寿命", secondary_y=False)fig.update_yaxes(title_text="<b>secondary</b>--人均GDG水平--千元", secondary_y=True)return fig.show()Get_Two_Bar_One_Line(df,"泰国")#Get a dataset of a dedicated countrydf = px.data.gapminder().query("country == <'Japan'>") #'Japan','Germany','Italy','Canada','Spain','Thailand','Argentina'df<"life"> = df<"lifeExp">.astype(int)df<"pop-Million"> = (df<"pop">/1000000).astype(int) #Get pop 100W /人口数量以百万单位来显示df<"gdpPercap-Thousand"> = (df<"gdpPercap">/1000).astype(float) #Get gdpPercap as Tousand /人均GDP以千元单位显示df<"Year"> = df<"year">.astype(str) #Convert year as int into stringdisplay(df)Get_Two_Bar_One_Line(df,"日本")#Get a dataset of a dedicated countrydf = px.data.gapminder().query("country == <'Vietnam'>") #'Japan','Germany','Italy','Canada','Spain','Thailand','Argentina'df<"life"> = df<"lifeExp">.astype(int)df<"pop-Million"> = (df<"pop">/1000000).astype(int) #Get pop 100W /人口数量以百万单位来显示df<"gdpPercap-Thousand"> = (df<"gdpPercap">/1000).astype(float) #Get gdpPercap as Tousand /人均GDP以千元单位显示df<"Year"> = df<"year">.astype(str) #Convert year as int into stringdisplay(df)Get_Two_Bar_One_Line(df,"越南")通过上面的内容看到,如何做好作图自定义函数是关键!!!方便后续调用并直接生成相关复杂图表,减少重复代码出现,现实中事先固定好几个模式的作图自定义函数,然后利用处理好的数据集直接生成优雅和统一的可视化报告,效率真的哇塞啊!!!!
END
我为人人,人人为我!!欢迎大家关注,点赞和转发!!!
【如何做柱状图和折线图的组合图 怎么做折线图】~~人生不是赛场,梦想不容退场~~不断努力学习蜕变出一个更好的自己,不断分享学习路上的收获和感悟帮助他人成就自己!!!