目前我正在绘制如下直方图:
我只想用等间距的直方图重新组合数据,但使用新的比例。我需要指定宽度,但由于 xscale,yscale 重置轴的方式,我不知道如何定义它。即在每种情况下(线性对数、对数对数等),应该做什么
ax.set_xlim(min(bin_edges), max(bin_edges))
ax.set_ylim(min(hist), max(hist))
设置为?或者有没有办法自动设置它,所以直方图看起来很正确,这完全基于我将 xscale 和 yscale 设置为“线性”或“对数”的事实。我确信有一个更简单的解决方案。目前,当我进入日志空间时,条形重叠并且宽度不同。
if self.xscale_hist == 'linear-linear':
ax.set_xscale("linear")
ax.set_yscale("linear")
hist, bin_edges = np.histogram(self.tmphistdata, bins=self.numhistbins)
width = (max(bin_edges)-min(bin_edges))/len(bin_edges)
self._display_points = ax.bar(bin_edges[:-1], hist, width = width, facecolor='green')
if self.xscale_hist == 'linear-log':
ax.set_xscale("linear")
ax.set_yscale("log")
hist, bin_edges = np.histogram(self.tmphistdata, bins=self.numhistbins)
hist = np.log10(hist)
width = (max(bin_edges)-min(bin_edges))/len(bin_edges)
self._display_points = ax.bar(bin_edges[:-1], hist, width = width, facecolor='green')
if self.xscale_hist == 'log-linear':
ax.set_xscale("log")
ax.set_yscale("linear")
hist, bin_edges = np.histogram(self.tmphistdata, bins=self.numhistbins)
bin_edges = np.log10(bin_edges)
width = (max(bin_edges)-min(bin_edges))/len(bin_edges)
self._display_points = ax.bar(bin_edges[:-1], hist, width = width, facecolor='green')
if self.xscale_hist == 'log-log':
ax.set_xscale("log")
ax.set_yscale("log")
hist, bin_edges = np.histogram(self.tmphistdata, bins=self.numhistbins)
bin_edges = np.log10(bin_edges)
hist = np.log10(hist)
width = (max(bin_edges)-min(bin_edges))/len(bin_edges)
self._display_points = ax.bar(bin_edges[:-1], hist, width = width, facecolor='green')