Ich mache eine Gruppe von Unterplots (z. B. 3 x 2) in matplotlib, aber ich habe weniger als 6 Datensätze. Wie kann ich die verbleibende Nebenhandlung leer machen?
Das Arrangement sieht so aus:
+----+----+
| 0,0| 0,1|
+----+----+
| 1,0| 1,1|
+----+----+
| 2,0| 2,1|
+----+----+
This may go on for several pages, but on the final page, there are, for example, 5 datasets to the 2,1 box will be empty. However, I have declared the figure as:
cfig,ax = plt.subplots(3,2)
So in the space for subplot 2,1 there is a default set of axes with ticks and labels. How can I programatically render that space blank and devoid of axes?
quelle
add_subplot()
clutter.A much improved subplot interface has been added to matplotlib since this question was first asked. Here you can create exactly the subplots you need without hiding the extras. In addition, the subplots can span additional rows or columns.
import pylab as plt ax1 = plt.subplot2grid((3,2),(0, 0)) ax2 = plt.subplot2grid((3,2),(0, 1)) ax3 = plt.subplot2grid((3,2),(1, 0)) ax4 = plt.subplot2grid((3,2),(1, 1)) ax5 = plt.subplot2grid((3,2),(2, 0)) plt.show()
quelle
It's also possible to hide a subplot using the Axes.set_visible() method.
import matplotlib.pyplot as plt import pandas as pd fig = plt.figure() data = pd.read_csv('sampledata.csv') for i in range(0,6): ax = fig.add_subplot(3,2,i+1) ax.plot(range(1,6), data[i]) if i == 5: ax.set_visible(False)
quelle
Would it be an option to create the subplots when you need them?
import matplotlib matplotlib.use("pdf") import matplotlib.pyplot as plt plt.figure() plt.gcf().add_subplot(421) plt.fill([0,0,1,1],[0,1,1,0]) plt.gcf().add_subplot(422) plt.fill([0,0,1,1],[0,1,1,0]) plt.gcf().add_subplot(423) plt.fill([0,0,1,1],[0,1,1,0]) plt.suptitle("Figure Title") plt.gcf().subplots_adjust(hspace=0.5,wspace=0.5) plt.savefig("outfig")
quelle