【问题标题】:matplotlib scatter plot change distance in x-axismatplotlib 散点图在 x 轴上的变化距离
【发布时间】:2014-10-13 11:49:34
【问题描述】:

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

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 轴,每个点之间的空间更小。我试图改变范围,但它不起作用。有人能帮我吗?

【问题讨论】:

  • 你只是想让你的身材整体“变窄”吗?如果是这样,您可以在 plt.subplots 命令中使用 figsize 关键字参数。如果你不只是想让你的身材变窄,那么你需要多说一点你想要什么。特别是,您是否希望在间距更紧密的 x 轴左侧、右侧或其他位置有额外的空白?
  • 1,2,3... 之间的距离应该更小,所以是更紧密的 x 轴。

标签: python matplotlib plot scatter-plot


【解决方案1】:

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

由于在您的情况下,图形已经创建,请使用 figure 对象的 set_size_inches 方法设置绘图的大小。

This question 包含一些其他方法可以做到这一点。

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

fig.set_size_inches(2,8)

给我这个:

我希望这是你想要做的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-24
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 2021-10-27
    相关资源
    最近更新 更多