我试图绘制一个 y 轴损坏的条形图。没有断轴,它看起来像这样: 没有断轴的绘图
轴断了,它看起来像这样:用断轴绘图
我想要图中没有断轴的 x-tick 标签,但我不知道怎么做!无论我尝试什么,只显示 9 个标签中的 5 个,并且总是缺少第一个标签,尽管它是计算 x-tick 标签的相同代码。
这是我用于没有断轴的情节的代码:
#computing dataframe
column1 = np.array(('Grünland','KA','MA','SG','SW','WG','WR','WW','ZR'))
column2 = np.array((1332.9,-429.7,-6041.6,-686.5,-72.4,-37.5,-4224.6,-4208.8,-3955.8))
column3 = np.array((1332.9,42.7,-1018.7,-32.7,21.7,-327.2,-3117.4,-15431.5,206.2))
data1 = np.column_stack((column1,column2,column3))
data = pd.DataFrame(data1,columns=['Frucht','SUM19','SUM20'])
data['SUM19'] = pd.to_numeric(data['SUM19'])
data['SUM20'] = pd.to_numeric(data['SUM20'])
labels = data['Frucht']
x = np.arange(len(labels)) # the label locations
width = 0.35 # the width of the bars
fig,bax = plt.subplots()
rects1 = bax.bar(x - width/2, data['SUM19'], width, label='2019')
rects2 = bax.bar(x + width/2, data['SUM20'], width, label='2020')
bax.set_xticks(x)
bax.set_xticklabels(labels)
这是带有断轴的图的代码(上面的数据相同):
fig = plt.figure()
bax = brokenaxes(ylims=((-16000,-15000), (-6500, 1500)),hspace=.05)
rects1 = bax.bar(x - width/2, data['SUM19'], width, label='2019')
rects2 = bax.bar(x + width/2, data['SUM20'], width, label='2020')
bax.set_xticks(x)
bax.set_xticklabels(labels)
非常感谢你的帮助 !!