颜色条限制不遵循数据限制
Color bar limits doesn't follow the data limits
我正在尝试用两个二维直方图绘制图表。我需要他们都有一个颜色条。但是,我能够在这些直方图之一的侧面绘制颜色条,但如下图所示,颜色条的限制并不反映直方图的限制。事件数较多的容器应该有大约 830 个事件。 (ps:我已经使用 im2.set_clim(vmin=0,vmax=10000)手动设置了颜色条的限制,但在此之前它是从 -20 到 20)。
我用来绘制的代码是这样的:
plt.set_cmap('gnuplot')
fig = plt.figure()
fig.set_size_inches(10, 10)
ax = fig.add_subplot(121,aspect='equal')
ax2 = fig.add_subplot(122, aspect='equal')
ax2.hist2d(data2,datay2,bins=(100,100), rasterized=True,range=np.array([(-7.9, 7.9), (-7.9, 7.9)]))
ax2.set_title('HMC with L=5.0 and t=1.5 ', size= 16, fontname='Comic Sans MS')
ax2.tick_params(axis='both', which='major', labelsize=10)
ax2.tick_params(axis='both', which='minor', labelsize=10)
ax.hist2d(data,datay,bins=(100,100), rasterized=True,range=np.array([(-7.9, 7.9), (-7.9, 7.9)]))
ax.set_title('NUTS ', size= 16, fontname='Comic Sans MS')
ax.tick_params(axis='both', which='major', labelsize=10)
ax.tick_params(axis='both', which='minor', labelsize=10)
#down here i am trying to plot the color map
im2 = ax2.imshow(chain,cmap ='gnuplot' ,interpolation='None')
divider = make_axes_locatable(ax2)
cax = divider.append_axes('right', size='5%', pad=0.05)
im2.set_clim(vmin=0, vmax=10000)
fig.colorbar(im2, cax=cax, orientation='vertical');
fig.text(0.5, 0.02, 'Generalized Coordinate', ha='center', size = 16)
fig.text(0.07, 0.5, 'Generalized Momenta', va='center', rotation='vertical',size = 16)
plt.savefig('2DHMCpog.pdf')
plt.savefig('2DHMCpog.png')
plt.show()
由此, you can use the return values of hist2d设置局部彩条。例如:
h = ax2.hist2d(data2,datay2,bins=(100,100), …
fig.colorbar(h[3], ax=ax2)
ax2.set_title('HMC with …
对第二个直方图执行相同的操作。
我正在尝试用两个二维直方图绘制图表。我需要他们都有一个颜色条。但是,我能够在这些直方图之一的侧面绘制颜色条,但如下图所示,颜色条的限制并不反映直方图的限制。事件数较多的容器应该有大约 830 个事件。 (ps:我已经使用 im2.set_clim(vmin=0,vmax=10000)手动设置了颜色条的限制,但在此之前它是从 -20 到 20)。
我用来绘制的代码是这样的:
plt.set_cmap('gnuplot')
fig = plt.figure()
fig.set_size_inches(10, 10)
ax = fig.add_subplot(121,aspect='equal')
ax2 = fig.add_subplot(122, aspect='equal')
ax2.hist2d(data2,datay2,bins=(100,100), rasterized=True,range=np.array([(-7.9, 7.9), (-7.9, 7.9)]))
ax2.set_title('HMC with L=5.0 and t=1.5 ', size= 16, fontname='Comic Sans MS')
ax2.tick_params(axis='both', which='major', labelsize=10)
ax2.tick_params(axis='both', which='minor', labelsize=10)
ax.hist2d(data,datay,bins=(100,100), rasterized=True,range=np.array([(-7.9, 7.9), (-7.9, 7.9)]))
ax.set_title('NUTS ', size= 16, fontname='Comic Sans MS')
ax.tick_params(axis='both', which='major', labelsize=10)
ax.tick_params(axis='both', which='minor', labelsize=10)
#down here i am trying to plot the color map
im2 = ax2.imshow(chain,cmap ='gnuplot' ,interpolation='None')
divider = make_axes_locatable(ax2)
cax = divider.append_axes('right', size='5%', pad=0.05)
im2.set_clim(vmin=0, vmax=10000)
fig.colorbar(im2, cax=cax, orientation='vertical');
fig.text(0.5, 0.02, 'Generalized Coordinate', ha='center', size = 16)
fig.text(0.07, 0.5, 'Generalized Momenta', va='center', rotation='vertical',size = 16)
plt.savefig('2DHMCpog.pdf')
plt.savefig('2DHMCpog.png')
plt.show()
由此
h = ax2.hist2d(data2,datay2,bins=(100,100), …
fig.colorbar(h[3], ax=ax2)
ax2.set_title('HMC with …
对第二个直方图执行相同的操作。