In [5]:
import sys
import os
sys.path.append(os.path.join(os.getcwd(),'pyrecharts'))

In [6]:
from IPython.display import display,HTML

In [8]:
from pyrecharts import StdCharts

Horizontal Bar Charts

  • Best suited for categories comparison

Example 1: default options, "as is"


In [9]:
data = dict(
    labels=['Bananas','Apples','Oranges','Watermelons','Grapes','Kiwis'],
    values=[4000,8000,3000,1600,1000,2500]
)
out = StdCharts.HBar(data)
HTML(out)


Out[9]:

Bananas 4000 Apples 8000 Oranges 3000 Watermelons 1600 Grapes 1000 Kiwis 2500

You can also save your chart with the save method:


In [10]:
StdCharts.save(out,'report_chart.png')

Example 2: sample options, sorting enabled


In [11]:
data = dict(
    labels=['Bananas','Apples','Oranges','Watermelons','Grapes','Kiwis'],
    values=[4000,8000,3000,1600,1000,2500]
)
out = StdCharts.HBar(
    data = data,
    width=600,
    color='#996666',
    title='Fruit prices ($)',
    source='Source: Local Market',
    fill='rgb(220, 75, 30)',
    values_sorted=True,
    paper='#f6f6f6',
    locale='en',
    font='Tahoma')
HTML(out)


Out[11]:

Fruit prices ($)

Apples 8,000 Bananas 4,000 Oranges 3,000 Kiwis 2,500 Watermelons 1,600 Grapes 1,000
Source: Local Market

Vertical Bar Charts

  • Ideal for a small number of labels or a portion of time dependent values
  • Fixed width

Example 3: defaults


In [12]:
data = dict(
    labels=[2010,2011,2012,2013,2014,2015,2016,2017],
    values=[4000,8000,3000,1600,1000,2500,4300,4200]
)
out = StdCharts.VBar(data=data,paper='#f3f3f3')
HTML(out)


Out[12]:

2010 4000 2011 8000 2012 3000 2013 1600 2014 1000 2015 2500 2016 4300 2017 4200

In [13]:
StdCharts.save(out,'report_vertical.png')

Example 4


In [14]:
data = dict(
    labels=['City ABCD','City EFGHM','City OPQRSTUV'],
    values=[200,100,500]
)
out = StdCharts.VBar(data=data,values_sorted=True,color="#446699",fill="#999999")
HTML(out)


Out[14]:

City OPQRSTUV 500 City ABCD 200 City EFGHM 100