如何使用 pylab 绘制没有边框的数据

发布于 2024-11-30 10:03:58 字数 1169 浏览 1 评论 0原文

使用 pylab,我想将没有轴或边框的数据绘制到 png 文件中。在下面的代码中,我仍然得到数据左侧和右侧的边框。

import pylab
scores = [[ 82.,78.,    71.5,   76.,    79.5,   77.,    73.5,   70.5,   74.,    74.5 ],
[ 79. ,  75.75, 71.,   76.,   78.25, 73.25, 72.25 ,73.25, 74.75, 73.5 ],
[ 77.,   75.,   70.5,  73. ,  77.,   73.5,  71.75, 75.25, 76.75, 74.  ],
[ 76.,   74.75, 72.5,  72.25 ,75.25, 76.5,  73.5,  73.,   75.25, 75.75],
[ 75.,   72.5,  72.25, 74.5,  73.25, 73.25, 74.5,  73.25, 73.5,  76.5 ],
[ 74.5,  72.,   69.5,  73.25,  73.75,  72.,    76.75,  77.,    74.25,  76.5 ],
[ 72.5,   73.75,  72.75,  75.75,  78.,    76.75,  77.75,  78.75,  77.25,  74.  ],
[ 74.5,   74.25,  74.75,  78.75,  80.75,  79.25,  74.5,   75.,    76.25,  73.  ],
[ 75.5,   71.5,   71.75,  78.75,  80.25,  77.5,   75.,    73.25,  72.25,  72.75],
[ 77.5,   74.5,   72.,    77.75,  78.25,  74.,    76.75,  75.75,  74.25,  73.  ]]

fig = pylab.figure()
ax = fig.add_subplot(111)
ax.xaxis.set_ticklabels([None])
ax.yaxis.set_ticklabels([None])
ax.xaxis.set_ticks([None])
ax.yaxis.set_ticks([None])
ax.imshow(scores,vmin=0, vmax=100, origin='lower')
pylab.savefig('output.png',bbox_inches='tight', pad_inches=0)

Using pylab, I want to plot just the data with no axes or borders to a png file. In code below, I still get borders to the left and right of the data.

import pylab
scores = [[ 82.,78.,    71.5,   76.,    79.5,   77.,    73.5,   70.5,   74.,    74.5 ],
[ 79. ,  75.75, 71.,   76.,   78.25, 73.25, 72.25 ,73.25, 74.75, 73.5 ],
[ 77.,   75.,   70.5,  73. ,  77.,   73.5,  71.75, 75.25, 76.75, 74.  ],
[ 76.,   74.75, 72.5,  72.25 ,75.25, 76.5,  73.5,  73.,   75.25, 75.75],
[ 75.,   72.5,  72.25, 74.5,  73.25, 73.25, 74.5,  73.25, 73.5,  76.5 ],
[ 74.5,  72.,   69.5,  73.25,  73.75,  72.,    76.75,  77.,    74.25,  76.5 ],
[ 72.5,   73.75,  72.75,  75.75,  78.,    76.75,  77.75,  78.75,  77.25,  74.  ],
[ 74.5,   74.25,  74.75,  78.75,  80.75,  79.25,  74.5,   75.,    76.25,  73.  ],
[ 75.5,   71.5,   71.75,  78.75,  80.25,  77.5,   75.,    73.25,  72.25,  72.75],
[ 77.5,   74.5,   72.,    77.75,  78.25,  74.,    76.75,  75.75,  74.25,  73.  ]]

fig = pylab.figure()
ax = fig.add_subplot(111)
ax.xaxis.set_ticklabels([None])
ax.yaxis.set_ticklabels([None])
ax.xaxis.set_ticks([None])
ax.yaxis.set_ticks([None])
ax.imshow(scores,vmin=0, vmax=100, origin='lower')
pylab.savefig('output.png',bbox_inches='tight', pad_inches=0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記柔刀 2024-12-07 10:03:58
import pylab
scores = [[ 82.,78.,    71.5,   76.,    79.5,   77.,    73.5,   70.5,   74.,    74.5 ],
[ 79. ,  75.75, 71.,   76.,   78.25, 73.25, 72.25 ,73.25, 74.75, 73.5 ],
[ 77.,   75.,   70.5,  73. ,  77.,   73.5,  71.75, 75.25, 76.75, 74.  ],
[ 76.,   74.75, 72.5,  72.25 ,75.25, 76.5,  73.5,  73.,   75.25, 75.75],
[ 75.,   72.5,  72.25, 74.5,  73.25, 73.25, 74.5,  73.25, 73.5,  76.5 ],
[ 74.5,  72.,   69.5,  73.25,  73.75,  72.,    76.75,  77.,    74.25,  76.5 ],
[ 72.5,   73.75,  72.75,  75.75,  78.,    76.75,  77.75,  78.75,  77.25,  74.  ],
[ 74.5,   74.25,  74.75,  78.75,  80.75,  79.25,  74.5,   75.,    76.25,  73.  ],
[ 75.5,   71.5,   71.75,  78.75,  80.25,  77.5,   75.,    73.25,  72.25,  72.75],
[ 77.5,   74.5,   72.,    77.75,  78.25,  74.,    76.75,  75.75,  74.25,  73.  ]]

fig = pylab.figure(frameon=False)
ax_size = [0,0,1,1]
fig.add_axes(ax_size)
pylab.imshow(scores,vmin=0, vmax=100, origin='lower')
pylab.axis('off')
## As you noted.
pylab.savefig('output.png',bbox_inches='tight', pad_inches=0)

这应该可以做到。没有为我显示任何轴。我所做的只是添加frameon=False

import pylab
scores = [[ 82.,78.,    71.5,   76.,    79.5,   77.,    73.5,   70.5,   74.,    74.5 ],
[ 79. ,  75.75, 71.,   76.,   78.25, 73.25, 72.25 ,73.25, 74.75, 73.5 ],
[ 77.,   75.,   70.5,  73. ,  77.,   73.5,  71.75, 75.25, 76.75, 74.  ],
[ 76.,   74.75, 72.5,  72.25 ,75.25, 76.5,  73.5,  73.,   75.25, 75.75],
[ 75.,   72.5,  72.25, 74.5,  73.25, 73.25, 74.5,  73.25, 73.5,  76.5 ],
[ 74.5,  72.,   69.5,  73.25,  73.75,  72.,    76.75,  77.,    74.25,  76.5 ],
[ 72.5,   73.75,  72.75,  75.75,  78.,    76.75,  77.75,  78.75,  77.25,  74.  ],
[ 74.5,   74.25,  74.75,  78.75,  80.75,  79.25,  74.5,   75.,    76.25,  73.  ],
[ 75.5,   71.5,   71.75,  78.75,  80.25,  77.5,   75.,    73.25,  72.25,  72.75],
[ 77.5,   74.5,   72.,    77.75,  78.25,  74.,    76.75,  75.75,  74.25,  73.  ]]

fig = pylab.figure(frameon=False)
ax_size = [0,0,1,1]
fig.add_axes(ax_size)
pylab.imshow(scores,vmin=0, vmax=100, origin='lower')
pylab.axis('off')
## As you noted.
pylab.savefig('output.png',bbox_inches='tight', pad_inches=0)

This should do it. Doesnt show any axises for me. All I did was add frameon=False.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文