Bar Charts

Bar charts are a helpful way to visualize categorical summaries such as mean and counts, in a side-by-side comparison. They can often help understand the cross-distribution of the dataset. This example looks at the Electric Vehicle population in the State of Washington.

import pygal
import numpy as np
import pandas as pd 


cars = pd.read_csv('dataset/Electric_Vehicle_Population_Data.csv')
electric_cars = cars.groupby(['Make'])['VIN (1-10)'].count() #.agg({ 'VIN (1-10)': 'count' })
electric_cars.head()
Make AUDI 2332 AZURE DYNAMICS 7 BENTLEY 3 BMW 4680 CADILLAC 108 Name: VIN (1-10), dtype: int64
bar = pygal.Bar( x_label_rotation= -40 )

bar.title = 'Electric Vehicle Population in WA'
for x in electric_cars.items():
    bar.add(x[0], x[1])

bar.render_in_browser()
Electric Vehicle Population in WA 0 0 10000 10000 20000 20000 30000 30000 40000 40000 50000 50000 2332 51.868325791855206 512.2346258718431 7 66.31266968325792 523.6962610817502 3 80.75701357466062 523.7159800240468 4680 95.20135746606334 500.6596067437306 108 109.64570135746605 523.1983577887606 10182 124.09004524886876 473.5362016147377 1794 138.53438914027151 514.8868236107378 822 152.97873303167424 519.678526588815 20 167.42307692307693 523.6321745192862 5819 181.86742081447966 495.0446379247697 18 196.31176470588238 523.6420339904345 792 210.7561085972851 519.8264186560397 1412 225.2004524886878 516.7699826000644 219 239.64479638009053 522.6511571400297 1152 254.08914027149325 518.0517138493444 4483 268.5334841628959 501.63076465183883 38 282.97782805429864 523.5434392789514 33 297.42217194570134 523.5680879568222 168 311.86651583710403 522.9025736543115 65 326.3108597285068 523.4103364184493 506 340.7552036199095 521.2363230302476 632 355.1995475113122 520.6151763479043 588 369.6438914027149 520.832084713167 12880 384.0882352941176 460.2357750356714 558 398.5325791855203 520.9799767803916 818 412.9769230769231 519.6982455311116 885 427.42126696832577 519.3679532476433 273 441.86561085972846 522.3849514190254 59 456.3099547511312 523.4399148318942 52078 470.7542986425339 267.0 3 485.1986425339366 523.7159800240468 4405 499.64298642533936 502.0152840266228 2514 514.087330316742 511.3374139973472 2288 528.5316742081448 512.4515342371059 Electric Vehicle Population in WA AUDI AZURE DYNAMICS BENTLEY BMW CADILLAC CHEVROLET CHRYSLER FIAT FISKER FORD GENESIS HONDA HYUNDAI JAGUAR JEEP KIA LAND ROVER LEXUS LINCOLN LUCID MOTORS MERCEDES-BENZ MINI MITSUBISHI NISSAN POLESTAR PORSCHE RIVIAN SMART SUBARU TESLA TH!NK TOYOTA VOLKSWAGEN VOLVO