import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt
np.random.seed(1000) y = np.random.standard_normal(20) x = range(len(y)) plt.plot(x, y)
plt.show()
1.2 Adding layers
## Showing change of each movements plt.ion() plt.show()
np.random.seed(2000) y = np.random.standard_normal((20,2)).cumsum(axis=0)
plt.figure(figsize=(7, 4)) # adding a canves figsize=(width, height) plt.plot(y.cumsum(), 'm',lw=1.5) # adding a line plt.plot(y.cumsum(), 'ro') # adding dots plt.grid(True) # adding grid on panals plt.axis('tight') # adding... I don't know plt.xlabel('index') # adding a title x plt.ylabel('value') # addint a title y plt.title('A Simple Plot') # adding a title
1.3 Facet(subplot)
plt.ion() plt.show()
## Data set np.random.seed(2000) y = np.random.standard_normal((20,2)).cumsum(axis=0)
plt.figure(figsize=(7,5)) plt.subplot(211) ''' 211: 2: 2 plot in a column; 1: 1 plot in a row 1: the 1sd ''' plt.plot(y[:, 0], lw=1.5, label='1st') plt.plot(y[:, 0], 'ro') plt.grid(True) plt.legend(loc=0) plt.axis('tight') plt.ylabel('value') plt.title('A Simple Plot')
plt.subplot(212) # the second plt.plot(y[:, 1], 'g', lw=1.5, label='2nd') plt.plot(y[:, 1], 'ro') plt.grid(True) plt.legend(loc=0) plt.axis('tight') plt.xlabel('index') plt.ylabel('value')
# default plot plt.scatter(x= TB_Sp.Frame, y = TB_Sp.value, color = 'black', alpha = .1) # Adding color to the edge plt.scatter(x= TB_Sp.Frame, y = TB_Sp.value, color = 'black', alpha = .1, edgecolors = 'steelblue') # remove the edges from each point plt.scatter(x= TB_Sp.Frame, y = TB_Sp.value, color = 'black', alpha = .1, linewidths= 0 )
Default
Edge with Color
No Edge
2.3 Line plot
y = np.random.standard_normal(20) x = range(len(y)) plt.plot(y, lw=1.5, label='1st')
2.4 Bar plot
2.4.1 Bar plot
y = np.random.standard_normal(20) x = range(len(y)) plt.bar(np.arange(len(y)), y, width=0.5, color='g', label='2nd')
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import math
y = [] for t inrange(100): y += [np.sin(2*math.pi * (0 - t/100))]
x = np.array([0] * 100) y = np.array(y)
fig, ax = plt.subplots() line, = ax.plot(x, y, 'o')
defupdate(num, x, y, line): line.set_data(x[num], y[num]) return line,
ani = animation.FuncAnimation(fig, update, len(x), interval=10, fargs=[x, y, line], blit=True) ani.save('animation_drawing.gif', writer='imagemagick', fps=60)
plt.plot(np.array(range(100))/10, y, 'o') plt.savefig('wave.png') plt.show()
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import math
frame = 100
Y = []
for x in range(10):
y = []
for t in range(frame):
y += [np.sin(2*math.pi * (x/10 - t/10/10))]
Y += [np.array(y)]
Y = np.array(Y)
X = np.array([[i] * frame for i in range(len(Y))])
fig, ax = plt.subplots()
line, = ax.plot([0, 10], [-1, 1], 'o')
ax.set_ylim(-1)
def update(num, x, y, line):
line.set_data(x[:,num], y[:,num])
return line,
ani = animation.FuncAnimation(fig, update, frame, interval=100,
fargs=[X, Y, line], blit=True )
ani.save('animation_drawing.gif', writer='imagemagick', fps=60)
plt.plot(np.array(range(100))/10, y, 'o')
plt.savefig('wave.png')
plt.show()
`