Ich habe einen Code (unten als minimal Ausführungsbeispiel gezeigt, MWE
), die eine Warnung erzeugt, wenn ein colorbar Plotten:Fang matplotlib Warnung
/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py:1533: UserWarning: This figure includes Axes that are not compatible with tight_layout, so its results might be incorrect.
warnings.warn("This figure includes Axes that are not "
Ich mag diese Warnung fangen, damit es nicht angezeigt wird.
Ich weiß, ich sollte etwas in Anlehnung an das, was in dieser Frage How do I catch a numpy warning like it's an exception (not just for testing)? angegeben ist, aber ich bin mir nicht sicher, wie es geht.
Hier ist die MWE
:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.gridspec as gridspec
x = np.random.randn(60)
y = np.random.randn(60)
z = [np.random.random() for _ in range(60)]
fig = plt.figure()
gs = gridspec.GridSpec(1, 2)
ax0 = plt.subplot(gs[0, 0])
plt.scatter(x, y, s=20)
ax1 = plt.subplot(gs[0, 1])
cm = plt.cm.get_cmap('RdYlBu_r')
plt.scatter(x, y, s=20 ,c=z, cmap=cm)
cbaxes = fig.add_axes([0.6, 0.12, 0.1, 0.02])
plt.colorbar(cax=cbaxes, ticks=[0.,1], orientation='horizontal')
fig.tight_layout()
plt.show()
Das ist genau das, was ich am Ende mit Brycepg, danke für Ihre Antwort! – Gabriel