首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >matplotlib散点图x轴变化距离

matplotlib散点图x轴变化距离
EN

Stack Overflow用户
提问于 2014-10-13 19:49:35
回答 1查看 2.9K关注 0票数 2

我想用Matplotlib散点图绘制一些数据。我使用以下代码将数据绘制为散点,并对不同的子图使用相同的轴。

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt

epsilon= np.array([1,2,3,4,5])

f, (ax1, ax2, ax3, ax4) = plt.subplots(4, sharex= True, sharey=True)
ax1.scatter(epsilon, mean_percent_100_0, color='r', label='Totaldehnung= 0.000')
ax1.scatter(epsilon, mean_percent_100_03, color='g',label='Totaldehnung= 0.003')
ax1.scatter(epsilon, mean_percent_100_05, color='b',label='Totaldehnung= 0.005')
ax1.set_title('TOR_R')
ax2.scatter(epsilon, mean_percent_111_0,color='r')
ax2.scatter(epsilon, mean_percent_111_03,color='g')
ax2.scatter(epsilon, mean_percent_111_05,color='b')
ax3.scatter(epsilon, mean_percent_110_0,color='r')
ax3.scatter(epsilon, mean_percent_110_03,color='g')
ax3.scatter(epsilon, mean_percent_110_05,color='b')
ax4.scatter(epsilon, mean_percent_234_0,color='r')
ax4.scatter(epsilon, mean_percent_234_03,color='g')
ax4.scatter(epsilon, mean_percent_234_05,color='b')

# Fine-tune figure; make subplots close to each other and hide x ticks for
# all but bottom plot.
f.subplots_adjust(hspace=0.13)
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
plt.locator_params(axis = 'y', nbins = 4)

ax1.grid()
ax2.grid()
ax3.grid()
ax4.grid()

plt.show()

现在我想要一个x轴,每个点之间的间距更小。我试着改变范围,但它不工作。有人能帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2014-10-14 17:31:42

要使x刻度更接近,您可能需要设置图形的尺寸。

因为在您的示例中,图形已经创建,所以使用figure对象的set_size_inches方法设置绘图的大小。

This question包含一些其他的方法来做同样的事情。

plt.show()之前添加以下行

代码语言:javascript
复制
fig.set_size_inches(2,8)

给了我这个:

我希望这就是你想要做的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26339307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档