helpless
helpless

Reputation: 13

How do I change the y axis of the bar graph?

Currently, I have plot out a bar graph for different regions like Africa, Americas using jupyter. However, once I plot out the graph, I find that for Africa, it seems to look like it is zero on the bar graph, so is there a way to change it? i would also like to add a graph title and add a y and x axis name to it.

Here is my code:

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

iplot(trace1)

Upvotes: 0

Views: 139

Answers (1)

M_S_N
M_S_N

Reputation: 2810

Reason your Bar for Africa is close to zero is the value is to small as compared to other values. You could try to increase fig size.

For title Try this

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')

Another Solution:

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')

Upvotes: 1

Related Questions