Ich habe eine Reihe von Handlungsstränge, die jeweils eine colorbar erfordern. Wenn ich jedes Teilplot plotten, ohne die X-Grenzen zu setzen, erstreckt sich die X-Achse über den Bereich meiner Daten hinaus und zeigt viel Leerraum. Ich verwende diesen Code:Wie x Grenzen in subplot einzustellen, ohne colorbar Schrumpfung
import matplotlib.pyplot as plt
from matplotlib.mlab import griddata
from numpy import ma
from mpl_toolkits.axes_grid1 import make_axes_locatable
def plot_threshold(ax):
""" plot boundary condition (solid) and
extrapolated condition(dotted)"""
x = np.arange(0,10,.5)
slide= Threshold(x)
ax.plot(slide[0], slide[1], 'r-',
linewidth=2)
ex_slide = Extrapolated_threshold(x)
ax.plot(ex_slide[0], ex_slide[1], 'r:')
def make_subplot(ax, x, y, zdata, title):
ax.set_title(title, size =14)
CS = ax.tricontourf(x, y, zdata, 100, cmap=clrmap)
plot_threshold(ax)
#TROUBLESOM LINE BELOW
plt.xlim(0,xmax)
# create divider for existing axes instance
divider = make_axes_locatable(ax)
# append axes to rhe right of ax, with 5% width of ax
cax1 = divider.append_axes('right', size='4%', pad = 0.1)
# create color bar in the appneded axes
cbar = plt.colorbar(CS, cax=cax1)
clrmap = plt.cm.viridis
# Three subplots, stacked vertically
fig, axarr = plt.subplots(3, figsize =(8,10), sharex='col')
make_subplot(axarr[0], x, y, z1, "Plot 1")
make_subplot(axarr[1], x, y, z2, 'Plot 2')
make_subplot(axarr[2], x, y, z3, 'Plot 3')
Wenn ich plt.xlim()
an die make_subplot
Funktion der colorbar der beiden führenden Nebenhandlungen werden extrem schmal und nicht lesbar hinzuzufügen. Die Farbleiste des dritten Subplots ist davon nicht betroffen.
der plt.xlim()
von make_subplot
aus- und es unter den Funktionsaufrufe hinzufügen, wie folgt aus:
make_subplot(axarr[0], x, y, z1, "Plot 1")
plt.xlim(0,14)
make_subplot(axarr[1], x, y, z2, 'Plot 2')
plt.xlim(0,14)
make_subplot(axarr[2], x, y, z3, 'Plot 3')
plt.xlim(0,14)
nicht die x Grenzen nicht anpassen und die Farbbalken zermatscht.
1) Warum werden die Farbbalken nicht alle die gleiche Art und Weise durch die Linie in make_subplots
betroffen?
2) Wie kann ich die x Grenzen einstellen, während glücklich Farbbalken zu halten?
Sie hatten Recht über die Verwendung von 'set_xlim' aber es benötigt innerhalb von' make_subplot' als 'ax.set_xlim (0,14)' verwendet werden soll. – Caroline