Pyplot matplotlib
Posted on September 2, 2022
Tags: codeetc
1 plt
2 single subplots()
Everytime we need to plot we must reinstantiate object with plt.subplots()
= plt.subplots()
fig, ax
ax.plot(...)
plt.show()
= plt.subplots()
fig, ax
ax.plot(...) plt.show()
= plt.subplots()
fig, ax "sigma aka Std")
ax.set_xlabel("Prob")
ax.set_ylabel(
ax.plot(..) plt.show()
3 multiplot subplot
= plt.subplots(2,2)
fig,ax 0,0].plot(arr) #top left
ax[0,1].plot(arr) #top right
ax[1,0].plot(arr)
ax[1,1].plot(arr)
ax[
fig.show()
=plt.imread("painting.png")
painting
plt.imshow(painting)-1]) #mirror image in x direction plt.imshow(painting[:,::
4 subplots quirk - axes can be: non-array, 1D, 2D
axes parameter is usually a 2d array ax[2,3].plot(arr)
When using subplots for (1,1) which is 1 graph, axes parmeter is not an array of subplots but a single plot ax.plot(arr)
= plt.subplots(1,1) #this same as line below
fig,ax #fig,ax = plt.subplots()
0,0].plot(arr) ###WILL RETURN ERROR
ax[###OK
ax.plot(arr) fig.show()
When using subplots where any parameter is (n,1) or (1,n), the axes parameter is a single array. ax[3].plot(arr)
= plt.subplots(1,2) #this same as line below
fig,ax
0,0].plot(arr) ###WILL RETURN ERROR
ax[
0].plot(arr) ###OK
ax[1].plot(arr)
ax[ fig.show()