-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTypes of plots.txt
112 lines (72 loc) · 2.39 KB
/
Types of plots.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Line Plot
A line plot is a way to display data along a number line. It is typically used to visualize the relationship between two continuous variables.
import matplotlib.pyplot as plt
# Create a line plot
plt.plot(x, y)
# Add labels and title
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Line Plot')
# Show plot
plt.show()
Scatter Plot
A scatter plot is a way to display the relationship between two variables. It is typically used to visualize the relationship between two continuous variables.
import matplotlib.pyplot as plt
# Create a scatter plot
plt.scatter(x, y)
# Add labels and title
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Scatter Plot')
# Show plot
plt.show()
Bar Plot
A bar plot is a way to display data using rectangular bars. It is typically used to visualize the relationship between a categorical variable and a continuous variable.
import matplotlib.pyplot as plt
# Create a bar plot
plt.bar(x, y)
# Add labels and title
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Bar Plot')
# Show plot
plt.show()
Histogram
A histogram is a way to display the distribution of a continuous variable. It is typically used to visualize the distribution of a single continuous variable.
import matplotlib.pyplot as plt
# Create a histogram
plt.hist(x)
# Add labels and title
plt.xlabel('X')
plt.ylabel('Frequency')
plt.title('Histogram')
# Show plot
plt.show()
Pie Chart
A pie chart is a way to display the proportions of a whole. It is typically used to visualize the distribution of a categorical variable.
import matplotlib.pyplot as plt
# Create a pie chart
plt.pie(sizes, labels=labels, autopct='%1.1f%%')
# Add title
plt.title('Pie Chart')
# Show plot
plt.show()
Subplots
Subplots allow you to display multiple plots in a single figure.
import matplotlib.pyplot as plt
# Create a figure with 2 rows and 2 columns
fig, ax = plt.subplots(2, 2)
# Plot data in the first subplot
ax[0, 0].plot(x, y)
# Plot data in the second subplot
ax[0, 1].scatter(x, y)
# Plot data in the third subplot
ax[1, 0].bar(x, y)
# Plot data in the fourth subplot
ax[1, 1].hist(x)
# Show plots
plt.show()
Key Takeaways
Choose the right plot type for the data and the question being asked.
Label plots clearly with titles, axis labels, and legend (if applicable).
Use subplots to display multiple plots in a single figure.