plt.plot(np.log(df['Total Cases']), np.log(df['Active']), 'go')
plt.subplot(1,3,1)
plt.plot(np.log(df['Total Cases']), np.log(df['Discharged']), 'b*')
plt.subplot(1,3,2)
plt.plot(np.log(df['Total Cases']), np.log(df['Deaths']), 'go')
plt.subplot(1,3,3)
plt.tight_layout()
plt.show()
I am running above code in jupyter notebook and kaggle kernel but 1st subplot is not showing any result while the other two subplots show output at 1st and 2nd place? how is it possible any code error or parameter missing?
CodePudding user response:
Let's step through your code line by line and see what happens
plt.plot(...'Active']), 'go')
creates an Axes over the whole Figure and plots on it.plt.subplot(1,3,1)
creates an Axes on the left of the Figure. As the docs say, "Creating a new Axes will delete any pre-existing Axes that overlaps with it beyond sharing a boundary". Since this new Axes overlaps with step 1's Axes, step 1's plot is deleted.plt.plot(...'Discharged']), 'b*')
plots on the current Axes, which was created in step 2.plt.subplot(1,3,2)
creates an Axes on the middle of the Figure.plt.plot(...'Deaths']), 'go')
plots on the current Axes, which was created in step 4plt.subplot(1,3,3)
creates an Axes on the right of the Figure. It remains blank because you don't plot anything on it afterwards.
You probably intended to create the Axes before each plot, so all 3 plots ends up on the Figure:
plt.subplot(1,3,1)
plt.plot(np.log(df['Total Cases']), np.log(df['Active']), 'go')
plt.subplot(1,3,2)
plt.plot(np.log(df['Total Cases']), np.log(df['Discharged']), 'b*')
plt.subplot(1,3,3)
plt.plot(np.log(df['Total Cases']), np.log(df['Deaths']), 'go')