这个解决方案满足吗?import matplotlib.pyplot as plt
list1 = [1,2,3,4]
list2 = [4,3,2,1]
somecondition = True
plt.figure(1) #create one of the figures that must appear with the chart
if not somecondition:
ax = plt.subplot(111) #create the first subplot that will ALWAYS be there
ax.plot(list1) #populate the "main" subplot
else:
ax = plt.subplot(211)
ax.plot(list1)
ax = plt.subplot(223) #create the second subplot, that MIGHT be there
ax.plot(list2) #populate the second subplot
plt.show()
如果您需要相同宽度但有一半高度的,最好使用matplotlib.gridspec,import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
list1 = [1,2,3,4]
list2 = [4,3,2,1]
somecondition = True
plt.figure(1) #create one of the f