-1

I am trying to depict two figures simultaneously in two different plots. I am getting though only one figure (the first one in particular).

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt
df = pd.read_excel("My excel.xlsx")
A1 = some value 
A2 = value 
A20 = value 
Z = value 

fig = plt.figure()
ax = fig.add_subplot()
ax.plot(Z,A1)
ax.plot(Z,A2)
ax.plot(Z,A3)
ax.plot(Z,A4)
ax.plot(Z,A5)
ax.plot(Z,A6)
ax.plot(Z,A20) 
plt.legend(loc = 'upper left')
plt.figure()
plt.show()

fig = plt.figure()
ax.plot = fig.add_subplot()
B1 = value 
B2 = value 
B3 = value 
B4 = value 
B20 = value 

ax.plt(Z,B1)
ax.plt(Z,B2)
ax.plt(Z,B20)
plt.legend(loc= 'upper left')
plt.figure()
plt.show()

I've seen a relevant post dealing with the same issue but was not able to come to a conclusion. Any help is welcome. Thank you in advance!

Jack21
  • 29
  • 8
  • Only call `plt.show()` once, at the end of your script. Also remove the extra `plt.figure()`, they will create empty figures. Your second figure plotting syntax is also not correct – DavidG Feb 26 '21 at 09:06
  • Still showing only the first graph. I am new to Python. But why is my syntax not correct regarding the second figure? – Jack21 Feb 26 '21 at 09:16

1 Answers1

1

Here's a link that might help you creating multiple subplots : https://matplotlib.org/stable/gallery/subplots_axes_and_figures/subplots_demo.html
I would also suggest to use list as arguments with plt.plot :
Use

ax.plt([Z, Z, Z], [B1, B2, B20])

instead of

ax.plt(Z,B1)
ax.plt(Z,B2)
ax.plt(Z,B20)
pierre
  • 44
  • 5