ProgrammingForDS12_viz
ProgrammingForDS12_viz
Liana Harutyunyan
Programming for Data Science
April 2, 2024
American University of Armenia
[email protected]
1
Main graph types
• lineplot
• scatterplot
• barplot
• histogram
• boxplot
• piechart
2
Plotting libraries
• Matplotlib
import matplotlib.pyplot as plt
• Seaborn
import seaborn as sns
3
Lineplot
4
Lineplot
plt.plot(data["yield apples"])
5
Lineplot
plt.plot(data["yield apples"])
5
Lineplots with labels
plt.xlabel("Years")
plt.ylabel("Yield of Apples")
plt.show()
6
Lineplot - multiple lines
• For two lines on the same graph, you just need two
plt.plots so that these are collected together and
pictured in one graph.
7
Lineplot
8
Figures
plt.figure(figsize=(12, 6))
9
Barplot
10
Plot Zoom-in
plt.ylim(0.8, 1)
11
Barplot
We can also stack bars on top of each other. Let’s plot the
data for apples and oranges.
bottom=data["yield apples"])
12
Histograms
plt.hist(data["yield apples"])
• It has bins parameter, that controls the number of bins
the data is represented.
13
Scatterplots
14
Boxplots
plt.boxplot(data["yield apples"])
15
Seaborn
16
Seaborn
17
Seaborn alternatives
• lineplot - sns.lineplot
18
Seaborn alternatives - Barplot
19
Seaborn alternatives - Barplot
data=tips df)
20
Seaborn alternatives - Histograms
Exercises:
21
Seaborn alternatives - Scatterplots
22
Seaborn - titles
23
Summary
Reading
https://www.simplilearn.com/tutorials/python-tutorial/data-
visualization-in-python
References
https://www.simplilearn.com/tutorials/python-tutorial/data-
visualization-in-python
Questions?
24