An error appears when you create the same axis object more than once. In your example, you first create two subplot objects (using the plt.subplot method).
type(plt.subplot(2, 1, 2)) Out: matplotlib.axes._subplots.AxesSubplot
Python automatically sets the last axis created by default. An axis simply means a frame for a graph without data. That is why you can execute plt.plot (data). The plot (data) method prints some data in your axis object. When you then try to print new data on the same graph, you cannot just use plt.subplot (2, 1, 2) again, because python is trying to create a new axis object by default. So what you have to do: assign each subplot to a variable.
ax1 = plt.subplot(2,1,1) ax2 = plt.subplot(2,1,2)
then select your "frame" into which you want to print the data:
ax1.plot(data) ax2.plot(data+1) ax1.plot(data+2)
If you are interested in building more charts (e.g. 5) on one shape, just create a shape first. Your data is stored in a DataFrame Pandas, and you create for each column a new axis element in the list. Then you iterate over the list and apply data to each element of the axis and select the attributes.
import pandas as pd import matplotlib.pyplot as plt
Robert Schirmer
source share