-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting.py
More file actions
51 lines (37 loc) · 1.15 KB
/
plotting.py
File metadata and controls
51 lines (37 loc) · 1.15 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
import matplotlib.pyplot as plt
import numpy as np
plt.close("all")
fig1 = plt.figure()
fig1, ax_lst = plt.subplots(
2, 2
) # creates a 2 by 2 figure list, if empty create 1 axes
# create a figure
fig1 = plt.figure()
# create the figure and axis
fig1, ax_lst = plt.subplots(2, 2)
# creates a 2 by 2 figure list, if empty create 1 axes
# axes is a single panel
# axis is each direction in the axes
# artist is every visible item
def my_plotter(ax, data1, data2, param_dict):
out = ax.plot(data1, data2, **param_dict)
return out
data1, data2, data3, data4 = np.random.randn(4, 100)
x = np.arange(100)
fig, ax = plt.subplots(1, 1)
data1, data2, data3, data4 = np.random.randn(4, 20)
x = np.arange(20)
# to get the xkcd style
# use in context manager since it changes many rcparams
with plt.xkcd():
my_plotter(ax, x, data2, {"marker": "x"})
plt.tight_layout()
plt.tight_layout()
my_plotter(ax_lst[0,0], x, data2, {"marker": "x"})
plt.tight_layout()
# unify legend for multiple graphs
ln1 = ax1.plot(xdata,ydata,label='data A')
ln2 = ax2.plot(xdata,ydata,label='data B')
lines = ln1+ln2
labels = [l.get_label() for l in lines]
ax1.legend(lines,labels)