gpt4 book ai didi

python - 如何使用 pylab 只绘制无边框的数据

转载 作者:太空宇宙 更新时间:2023-11-04 01:38:54 25 4
gpt4 key购买 nike

使用 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)

最佳答案

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

关于python - 如何使用 pylab 只绘制无边框的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7110897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com