简体   繁体   English

matplot python 中标签之间的间距

[英]Spacing between labels in matplot python

My problem is that I cannot distance the two labels, as the data are very similar to each other.我的问题是我无法区分这两个标签,因为数据彼此非常相似。 This is my code with an image attached.这是我的代码,附有图片。 What I tried: plt.xticks rotated the labels.我尝试了什么: plt.xticks 旋转了标签。

figure(figsize=(10, 10), dpi=80)

value=[96.3,91.8,39.6,33.3,32.4,34.2,30.6,31.5,11.7,27.9]


plt.plot([0.05,0.1,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50],valore, '--bo', label='line with marker')
plt.xticks([0.05,0.1,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50])
plt.yticks([96.3,91.8,39.6,33.3,32.4,34.2,30.6,31.5,11.7,27.9])
plt.tick_params(axis='y', direction='out')
#plt.yticks(rotation=45)
ax = plt.gca()
#ax.set_xlim([5, 50])
ax.set_ylim([11.0, 97.0])

plt.legend()
plt.show()

这就是我所拥有的

I want more space between 30.6 and 31.5 to make the result more readable我希望 30.6 和 31.5 之间有更多空间,以使结果更具可读性

You could use a broken axis (see example here ).您可以使用断轴(参见此处的示例)。

In your case, the code would look like that:在您的情况下,代码如下所示:

fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True,figsize=(10,10),dpi=80,gridspec_kw={'height_ratios':[1,10]})
fig.subplots_adjust(hspace=0.1)

value=np.array([96.3,91.8,39.6,33.3,32.4,34.2,30.6,31.5,11.7,27.9])
x=np.array([0.05,0.1,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50])

ax1.plot(x,value, '--bo', label='line with marker')
ax2.plot(x,value, '--bo', label='line with marker')
ax1.set_yticks(value)

ax2.set_yticks(value)
ax1.set_xticks([0.05,0.1,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50])
ax1.set_ylim(91,98)  # outliers only
ax2.set_ylim(10,40)

ax1.spines.bottom.set_visible(False)
ax2.spines.top.set_visible(False)
ax1.xaxis.tick_top()
ax1.tick_params(labeltop=False)  # don't put tick labels at the top
ax2.xaxis.tick_bottom()
d = .5  # proportion of vertical to horizontal extent of the slanted line
kwargs = dict(marker=[(-1, -d), (1, d)], markersize=12,
              linestyle="none", color='k', mec='k', mew=1, clip_on=False)
ax1.plot([0, 1], [0, 0], transform=ax1.transAxes, **kwargs)
ax2.plot([0, 1], [1, 1], transform=ax2.transAxes, **kwargs)

plt.legend()
plt.show()

And the output looks like the following: output 如下所示:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM