Voglio fare qualcosa di simile a http://matplotlib.org/examples/pylab_examples/hist2d_log_demo.html ma ho letto che usare pylab per codice diverso da Python in modalità interattiva è una cattiva pratica, quindi mi piacerebbe farlo con matplotlib.pyplot. Tuttavia, non riesco a capire come far funzionare questo codice usando pyplot. Utilizzando, pylab, l'esempio dato èCome si usa colorbar con hist2d in matplotlib.pyplot?
from matplotlib.colors import LogNorm
from pylab import *
#normal distribution center at x=0 and y=5
x = randn(100000)
y = randn(100000)+5
hist2d(x, y, bins=40, norm=LogNorm())
colorbar()
show()
Ho provato un po 'come
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
h1 = ax1.hist2d([1,2],[3,4])
e da qui ho provato di tutto da plt.colorbar(h1)
plt.colorbar(ax1)
plt.colorbar(fig)
ax.colorbar()
ecc ecc e non posso ottenere niente da lavorare.
In generale, onestamente non sono molto chiaro sulla relazione tra pylab e pyplot, anche dopo aver letto http://matplotlib.org/faq/usage_faq.html. Ad esempio show()
in pylab sembra diventare plt.show()
in pyplot, ma per qualche motivo colorbar
non diventa plt.colorbar()
?
Per esempio,
realtà 'colorbar' lascia in matplotlib stessa: [link] (http://matplotlib.org/api/colorbar_api.html). Quindi potresti voler importare matplotlib come mpl' e 'mpl.colorbar()'. – arbulgazar