【问题标题】:Create padding within plot在绘图内创建填充
【发布时间】:2014-06-29 19:18:27
【问题描述】:

我正在处理我用 QtDesigner 创建的 matplotlibwidget。

当我将我的测试点绘制到我的情节中时,它们大多排列在边界或交叉轴上。这对我来说看起来不是很熟悉。

所以我的问题是,我如何告诉 matplotlib 在绘图边界和测试点之间添加某种“内部填充”。因此,例如,如果我的最小值是“500”,我想将左边框绘制在 400 左右,所以在最小点和边框之间有一些边距。

提前谢谢你!

【问题讨论】:

标签: python matplotlib plot pyqt


【解决方案1】:

plt.margins 可用于调整数据周围的自动填充,如下所示。

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)
y = np.power(x, 3)

plt.plot(x, y, 'ro')

# Create a 5% (0.05) and 10% (0.1) padding in the 
# x and y directions respectively.
plt.margins(0.05, 0.1)

plt.show()

如果您的最小值为500,并且希望边框在400 附近,那么您可以选择0.2 的x 边距百分比,如plt.margins(0.2, 0.2)

【讨论】:

  • 这似乎不适用于子图(或者它可能会在整个图形周围增加空间,比例难以理解)。
猜你喜欢
  • 2021-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-07
  • 2011-08-03
  • 1970-01-01
  • 1970-01-01
  • 2011-06-16
相关资源
最近更新 更多