Learn graphing and visualization in Python
Matplotlib is the workhorse of python visualization. It is old but widely used.
Seaborn library aims to give pretty graphs and high level APIs.
- Graph libraries in Python - A good overview of graphics libraries in Python
- Python graph gallery is the ultimate website with lots of sample graph and code for both Matplot and Seaborn
- Visualization section from the excellent open source book Python Data Science Book
- Seaborn aims to give prettier graphs out of the box
- Seaborn section from the excellent open source book Python Data Science Book
- An excellent Seaborn tutorial with Pokemon dataset :-)
After completing the exercises below, you should be comfortable with
- Creating visualizations using matplot and seaborn
- What is the difference between Seaborn vs Matplotlib?
★☆☆ - Easy
★★☆ - Medium
★★★ - Challenging
★★★★ - Bonus
bills = [50,30,60,40,65,20,10,15,25,35]
tips= [12,7,13,8,15,5,2,2,3,4]
- Label x-axis as 'bill'
- Label y-axis as 'tip'
a = [22, 25, 30, 35, 40, 42, 45, 50, 55, 60, 65, 70]
month revenue
Jan 10
Feb 12
Mar 7
Apr 15
May 17
Gender percentage
M 52
F 40
Unknown 8
- Data: house-sales.csv
- Visualize the following
- Number of sales per bedrooms (bar plot or Pie)
- Average house price per bedrooms (box plot)
- Relationship between 'SQFT' vs 'Sale Price' (Scatter plot)
- Any other interesting plots you can come up with
Download pokemon data
Read it like this:
pokemon = pd.read_csv('https://s3.amazonaws.com/elephantscale-public/data/pokemon/pokemon-small.csv', index_col=0)
with pd.option_context("display.width", 150):
print (pokemon)
Data looks like this:
Name Type 1 Type 2 Total HP Attack Defense Sp. Atk Sp. Def Speed Stage Legendary
#
1 Bulbasaur Grass Poison 318 45 49 49 65 65 45 1 False
2 Ivysaur Grass Poison 405 60 62 63 80 80 60 2 False
3 Venusaur Grass Poison 525 80 82 83 100 100 80 3 False
4 Charmander Fire NaN 309 39 52 43 60 50 65 1 False
5 Charmeleon Fire NaN 405 58 64 58 80 65 80 2 False
.. ... ... ... ... ... ... ... ... ... ... ... ...
147 Dratini Dragon NaN 300 41 64 45 50 50 50 1 False
148 Dragonair Dragon NaN 420 61 84 65 70 70 70 2 False
149 Dragonite Dragon Flying 600 91 134 95 100 100 80 3 False
150 Mewtwo Psychic NaN 680 106 110 90 154 90 130 1 True
151 Mew Psychic NaN 600 100 100 100 100 100 100 1 False
Try the following graphs:
EX-1A - Do a graph to illustrate how many type-1 Pokemons
Hint: histogram
EX-1B - Illustrate Attack
points per Type-1
in a boxplot
Hint: You may need to find the average attack points per type first
Ex-1C - Come up with a graph to explain this data. Experiment