-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatplotlib_1.py
More file actions
134 lines (115 loc) · 4.63 KB
/
Copy pathmatplotlib_1.py
File metadata and controls
134 lines (115 loc) · 4.63 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import matplotlib.pyplot as plt
import numpy as np
# plt.plot([1, 2, 3, 4], [1, 2, 3, 4])
# plt.plot([2, 3, 4, 5], [1, 2, 3, 4], [3, 4, 5, 6], [1, 2, 3, 4]) # plotting two lines in single line
# plt.plot([x for x in range(4, 8)], [y for y in range(1, 5)]) # using list comprehension to generate array for chart
# plt.show()
# using numpy
# x = np.arange(1, 5)
# plt.plot(x, x, x, x * 3, x, x / 2)
# plt.xlabel("This is the x axis")
# plt.ylabel("This is the y axis")
# plt.title("This is the plot title")
# plt.legend(["x, x", "x, x * 3", "x, x / 2"])
# plt.show()
# # This example plots each curve separate with legend applied from keyword arg in each plot function
# x = np.arange(1, 5)
# plt.plot(x, x, label="x, x")
# plt.plot(x, x * 3, label="x, x * 3")
# plt.plot(x, x / 2, label="x, x / 2")
# plt.xlabel("This is the x axis")
# plt.ylabel("This is the y axis")
# plt.title("This is the plot title")
# plt.legend(loc="upper left")
# plt.show()
# # This example adds gridlines and manipulates the axes
# x = np.arange(1, 5)
# plt.plot(x, x, label="x, x")
# plt.plot(x, x * 3, label="x, x * 3")
# plt.plot(x, x / 2, label="x, x / 2")
# plt.xlabel("This is the x axis")
# plt.ylabel("This is the y axis")
# plt.title("This is the plot title")
# plt.legend(loc="upper left")
# plt.grid(True)
# plt.axis([0, 5, 0, 13]) # [x min, x max, y min, y max]
# plt.show()
# This example adds colour
# x = np.arange(1, 5)
# plt.plot(x, x, label="x, x", color="red") # can also pass abbreviations, RGB or hex color
# plt.plot(x, x * 3, "green" label="x, x * 3") # can also pass color as third argument
# plt.plot(x, x / 2, label="x, x / 2", color="blue")
# plt.xlabel("This is the x axis")
# plt.ylabel("This is the y axis")
# plt.title("This is the plot title")
# plt.legend(loc="upper left")
# plt.grid(True)
# plt.axis([0, 5, 0, 13])
# plt.show()
# # This example adds line and marker customisation
# x = np.arange(1, 5)
# plt.plot(x, x, ":d", label="x, x", color="red") # added 'd' as marker for data points
# plt.plot(x, x * 3, "g--s", label="x, x * 3") # note colour plus line style combined in third argument
# plt.plot(x, x / 2, "-.o", label="x, x / 2", color="blue")
# plt.xlabel("This is the x axis")
# plt.ylabel("This is the y axis")
# plt.title("This is the plot title")
# plt.legend(loc="upper left")
# plt.grid(True)
# plt.axis([0, 5, 0, 13])
# plt.show()
# This example adds line and marker customisation
# x = np.arange(1, 5)
# plt.plot(x, x, "d", label="x, x", color="red", linestyle="") # using linestyle kwarg
# plt.plot(x, x * 3, "g--s", label="x, x * 3", linewidth=3) # line width
# plt.plot(x, x / 2, "-.o", label="x, x / 2", color="blue",
# markersize=10, markeredgecolor="r", markerfacecolor="c") # marker size and coloring
# plt.xlabel("This is the x axis")
# plt.ylabel("This is the y axis")
# plt.title("This is the plot title")
# plt.legend(loc="upper left")
# plt.grid(True)
# plt.axis([0, 5, 0, 13])
# plt.show()
# Mulitple figures in same window
#
# fig = plt.figure() # create an figure instance
#
# chart1 = fig.add_subplot(3, 1, 1) # setup grid for charts and set position
# chart2 = fig.add_subplot(3, 1, 2) # (rows, columns, position)
# chart3 = fig.add_subplot(3, 1, 3)
#
# x = np.arange(1, 5)
# chart1.plot(x, x, "d", label="x, x", color="red", linestyle="") # changed to chart1 variable
# chart2.plot(x, x * 3, "g--s", label="x, x * 3", linewidth=3) #
# chart3.plot(x, x / 2, "-.o", label="x, x / 2", color="blue",
# markersize=10, markeredgecolor="r", markerfacecolor="c") #
# # plt.xlabel("This is the x axis")
# # plt.ylabel("This is the y axis")
# # plt.title("This is the plot title")
# plt.legend(loc="best")
#
# plt.grid(True)
# plt.axis([0, 5, 0, 13])
#
# plt.show()
fig = plt.figure(facecolor="grey") # specify background color
chart1 = fig.add_subplot(1, 1, 1, facecolor="black") # chart background color
# chart2 = fig.add_subplot(3, 1, 2) # (rows, columns, position)
# chart3 = fig.add_subplot(3, 1, 3)
x = np.arange(1, 5)
chart1.plot(x, x, "d", label="x, x", color="red", linestyle="--") # changed to chart1 variable
chart1.tick_params(axis="x", color="white") # set axis tick color
chart1.tick_params(axis="y", color="white") # set axis tick color
for spine in chart1.spines:
chart1.spines[spine].set_color("white") # set border/spines color
# chart2.plot(x, x * 3, "g--s", label="x, x * 3", linewidth=3) #
# chart3.plot(x, x / 2, "-.o", label="x, x / 2", color="blue",
# markersize=10, markeredgecolor="r", markerfacecolor="c") #
# plt.xlabel("This is the x axis")
# plt.ylabel("This is the y axis")
# plt.title("This is the plot title")
plt.legend(loc="best")
plt.grid(True)
# plt.axis([0, 5, 0, 13])
plt.show()