【问题标题】:matplotlib plot to fill figure only with data points, no borders, labels, axes,matplotlib 绘图仅用数据点填充图形,没有边框、标签、轴,
【发布时间】:2017-07-25 15:52:04
【问题描述】:

我追求 matplotlib 紧凑布局的极端形式。 我希望数据点从边到边填充图形 留下任何边界,没有标题、轴、刻度、标签或任何其他装饰。 我想做类似figimage 所做的事情,但要使用绘图而不是原始图像。

如何在 matplotlib 中做到这一点?

【问题讨论】:

标签: python matplotlib layout plot


【解决方案1】:

虽然可以从this question 的答案中找到解决方案,但乍一看可能并不明显。

在轴周围没有填充的主要想法是使轴与图形的大小相同。

fig = plt.figure()
ax = fig.add_axes([0,0,1,1])

或者,可以将外部间距设置为0

fig, ax = plt.subplots()
plt.subplots_adjust(left=0, right=1, bottom=0, top=1)

然后,为了移除可以使用的轴装饰

ax.set_axis_off()

ax.axis("off")

这现在可能仍会在绘制的线和边缘之间留下一些空间。这可以通过使用ax.set_xlim()ax.set_ylim() 适当地设置限制来消除。或者,使用ax.margins(0)

一个完整的例子可能看起来像

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.axis("off")

ax.plot([2,3,1])
ax.margins(0)

plt.show()

【讨论】:

    猜你喜欢
    • 2015-12-29
    • 2019-02-15
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-13
    • 1970-01-01
    相关资源
    最近更新 更多