如何更改条形图的y轴?

时间:2019-07-15 03:09:25

标签: python pandas plotly plotly-dash

目前,我已经使用jupyter绘制了非洲,美洲等不同地区的条形图。但是,一旦我绘制了图表,我发现对于非洲来说,条形图上看起来好像是零,那么有没有办法改变它呢?我还想添加一个图形标题,并为其添加y和x轴名称。

这是我的代码:

trace1 =[go.Bar(x=['Africa','Americas','Asia','Europe','Oceania'],y=[81054,1481595,36970456,2959948,3220564])]

iplot(trace1)

1 个答案:

答案 0 :(得分:0)

您的非洲标准接近于零,原因是该值与其他值相比较小。您可以尝试增加无花果的大小。

对于标题,请尝试

trace1 = {
  'x': ['Africa','Americas','Asia','Europe','Oceania'],
  'y': [81054,1481595,36970456,2959948,3220564],
  'name': 'Trace1',
  'type': 'bar'
}; 
data = [trace1];
layout = {
  'xaxis': {'title': 'Continents'},
  'yaxis': {'title': 'Population', "type":'log', 'autorange':True},
  'barmode': 'relative',
  'title': 'Name Title'
};
py.iplot({'data': data, 'layout': layout}, filename='barmode-relative')

另一种解决方案:

import pandas as pd
import numpy as np
%matplotlib inline

from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import cufflinks as cf
init_notebook_mode(connected=True)
cf.go_offline()

df = pd.DataFrame({'Continent':['Africa','Americas','Asia','Europe','Oceania'],'Population':[81054,1481595,36970456,2959948,3220564]})

df.iplot(kind='bar',x='Continent',y='Population',title='Name' xTitle='Continent', yTitle ='Population')
相关问题