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
| from matplotlib.ticker import FuncFormatter
import matplotlib.pyplot as plt
def save(filename):
plt.savefig(filename)
def show():
plt.show()
def bar(x,y,title=None,width=0.7):
fig, ax = plt.subplots()
ax.set_title(title if title is not None else '')
plt.bar(x,y,width=width)
def line(x,y,ylim=None,title=None,width=0.7):
fig, ax = plt.subplots()
ax.set_title(title if title is not None else '')
if ylim is not None: plt.ylim(ylim)
plt.plot(x,y)
def scatter(x,y,ylim=None,title=None,width=0.7):
fig, ax = plt.subplots()
ax.set_title(title if title is not None else '')
if ylim is not None: plt.ylim(ylim)
plt.scatter(x,y)
######################################################################
# TEST
######################################################################
def barTest():
x = [ 1, 2, 3, 4 ]
y = [ 15, 24, 32, 25 ]
bar(x,y,title="Bar Chart")
show()
def lineTest():
x = [ 'apple', 'banana', 'orange', 'peanut' ]
y = [ 15, 24, 32, 25 ]
line(x,y,ylim=(0,40),title="Line Chart")
show()
def scatterTest():
x = [ 'apple', 'banana', 'orange', 'peanut' ]
y = [ 15, 24, 32, 25 ]
scatter(x,y,ylim=(0,40),title="Line Chart")
show()
def multiTest():
x = [ 'apple', 'banana', 'orange', 'peanut' ]
y = [ 15, 24, 32, 25 ]
fig, axs = plt.subplots(1, 3, figsize=(9, 3), sharey=True)
axs[0].bar(x, y)
axs[1].plot(x, y)
axs[2].scatter(x, y)
axs[0].set_title('Bar')
axs[1].set_title('Line')
axs[2].set_title('Scatter')
fig.suptitle('Categorical Plotting')
show()
if __name__ == "__main__":
#barTest()
#lineTest()
#scatterTest()
multiTest()
pass
|
댓글 없음:
댓글 쓰기