Python matplotlib直方图上的Y轴中断

Python matplotlib直方图上的Y轴中断,python,matplotlib,histogram,yaxis,Python,Matplotlib,Histogram,Yaxis,我有以下柱状图: 它是由以下代码生成的: hist = plt.hist((df2.to_numpy().flatten()), 70, facecolor = "blue", alpha = 0.75) axes = plt.gca() axes.set_xlim([0,15]) axes.set_ylim([0,65000]) 我想在y轴上创建一个断点,以获得ylim=(0,70)和ylim=(7060000)。 有人能帮忙吗 提前谢谢 您能否更改上用户给出的示例?我认为这里的修复使用了

我有以下柱状图:

它是由以下代码生成的:

hist = plt.hist((df2.to_numpy().flatten()), 70, facecolor = "blue", alpha = 0.75)
axes = plt.gca()
axes.set_xlim([0,15])
axes.set_ylim([0,65000])
我想在y轴上创建一个断点,以获得
ylim=(0,70)
ylim=(7060000)。

有人能帮忙吗


提前谢谢

您能否更改上用户给出的示例?我认为这里的修复使用了matplotlib文档示例

import numpy as np
import matplotlib.pyplot as plt
data = np.random.randn(10000) * 0.5 + 3. # making some random data to bin
bin_edges = np.linspace(0, 6, 7) # make the bins
bin_centres = np.linspace(0.5, 6.5, 6) # for plotting only
my_hist = np.histogram(data, bins = bin_edges)[0]

f, (ax, ax2) = plt.subplot(2,1,sharex = True, facecolor = 'w') # make the axes
ax.bar(bin_centres, my_hist) # plot on top axes
ax2.bar(bin_centres, my_hist) # plot on bottom axes
ax.set_ylim([4600,4900]) # numbers here are specific to this example
ax2.set_ylim([0, 500]) # numbers here are specific to this example
ax.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax.xaxis.tick_bottom() 
ax.tick_params(labeltop=False)
ax2.xaxis.tick_bottom()
编辑:我想我的回答应该更具体一些,并举个例子

import numpy as np
import matplotlib.pyplot as plt
data = np.random.randn(10000) * 0.5 + 3. # making some random data to bin
bin_edges = np.linspace(0, 6, 7) # make the bins
bin_centres = np.linspace(0.5, 6.5, 6) # for plotting only
my_hist = np.histogram(data, bins = bin_edges)[0]

f, (ax, ax2) = plt.subplot(2,1,sharex = True, facecolor = 'w') # make the axes
ax.bar(bin_centres, my_hist) # plot on top axes
ax2.bar(bin_centres, my_hist) # plot on bottom axes
ax.set_ylim([4600,4900]) # numbers here are specific to this example
ax2.set_ylim([0, 500]) # numbers here are specific to this example
ax.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax.xaxis.tick_bottom() 
ax.tick_params(labeltop=False)
ax2.xaxis.tick_bottom()


我不太确定最后几行是怎么做的,但当我做它们的时候,它们给了我一个非常好的近似于我上面链接的例子。如果您想让它看起来更漂亮,那么您可以做更多的事情,请参阅matplotlib.pyplot.bar的文档和我链接的示例。

这看起来更像是一个注释,而不是一个答案。@我同意,所以当您评论时我已经编辑了我的回复:)我希望我的编辑更好,更像一个答案。请给我任何你认为有助于进一步改进答案的反馈。谢谢!在定义“my_hist”时,运行此命令会导致语法错误。我相信你错过了“bin_centres”代码末尾的“)”一行。修复此问题时,我得到一个新错误,该错误表示-TypeError:bar()缺少1个必需的位置参数:“height”:\我用brokenazes找到了解决问题的方法:)@user10934304我在打字时不小心在那一行上粘贴了一些东西。斧头不应该在那里。我现在已经更新了代码。我很高兴你解决了你的问题