matplotlib图以仅用数据点,无边界,标签,轴, [英] matplotlib plot to fill figure only with data points, no borders, labels, axes,

查看:102
本文介绍了matplotlib图以仅用数据点,无边界,标签,轴,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我追求的是matplotlib紧凑布局的极端形式. 我希望数据点从一个边缘到另一个边缘填充图形而没有 留下任何边界,没有标题,轴,刻度线,标签或任何其他装饰. 我想做figimage一样的事情,但要用绘图代替原始图像.

I am after an extreme form of matplotlib's tight layout. I would like the data points to fill the figure from edge to edge without leaving any borders and without titles, axes, ticks, labels or any other decorations. I want to do something like what figimage does, but for plots instead of raw images.

如何在matplotlib中做到这一点?

How do I do that in matplotlib?

推荐答案

虽然可以找到一个解决方案,将答案中的点点滴滴传到

While a solution may be found taking the bits and pieces from an answer to this question it may not be obvious at first sight.

在轴周围没有填充的主要思想是使轴与图形的尺寸相同.

The main idea to have no padding around the axes, is to make the axes the same size as the figure.

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

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

Alternatively, one can set the outer spacings to 0.

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

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

Then, in order to remove the axis decorations one can use

ax.set_axis_off()

ax.axis("off")

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

This may now still leave some space between the plotted line and the edge. This can be removed by setting the limits appropriately using ax.set_xlim() and ax.set_ylim(). Or, by using ax.margins(0)

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

A complete example may thus look like

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()

这篇关于matplotlib图以仅用数据点,无边界,标签,轴,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆