加载回文件后,matplotlib 图中的隐藏轴可见
hidden axis in a matplotlib plot is visible after loading back the file
我使用 中的代码生成了股票价格的蜡烛图。代码隐藏坐标轴一切正常
plt.figure()
width = 1
width2 = 0.1
pricesup = df[df.close >= df.open]
pricesdown = df[df.close < df.open]
plt.bar(pricesup.index, pricesup.close - pricesup.open, width, bottom=pricesup.open, color='g')
plt.bar(pricesup.index, pricesup.high - pricesup.close, width2, bottom=pricesup.close, color='g')
plt.bar(pricesup.index, pricesup.low - pricesup.open, width2, bottom=pricesup.open, color='g')
plt.bar(pricesdown.index, pricesdown.close - pricesdown.open, width, bottom=pricesdown.open, color='r')
plt.bar(pricesdown.index, pricesdown.high - pricesdown.open, width2, bottom=pricesdown.open, color='r')
plt.bar(pricesdown.index, pricesdown.low - pricesdown.close, width2, bottom=pricesdown.close, color='r')
plt.gca().set_axis_off()
plt.subplots_adjust(
top=1,
bottom=0,
right=1,
left=0,
hspace=0,
wspace=0
)
plt.margins(0, 0)
plt.savefig(file_path, bbox_inches='tight', format=file_format, dpi=72)
但是当我使用 TensorFlow decode_png 方法加载图像时,它显示隐藏轴:
image = tf.io.read_file('test.png')
image = tf.io.decode_png(image)
plt.imshow(image)
plt.show()
图片通过windows加载 图片:
使用 TensorFlow 库在 Pythin 中加载的图像:
这没有显示隐藏轴,您的图像没有第一个轴就可以正确保存。但是当您打开图像时 plt.imshow()
正在创建并显示一个新轴。在 plt.imshow(image)
之后添加 plt.axis('off')
行,它应该删除这个新轴。
我使用
plt.figure()
width = 1
width2 = 0.1
pricesup = df[df.close >= df.open]
pricesdown = df[df.close < df.open]
plt.bar(pricesup.index, pricesup.close - pricesup.open, width, bottom=pricesup.open, color='g')
plt.bar(pricesup.index, pricesup.high - pricesup.close, width2, bottom=pricesup.close, color='g')
plt.bar(pricesup.index, pricesup.low - pricesup.open, width2, bottom=pricesup.open, color='g')
plt.bar(pricesdown.index, pricesdown.close - pricesdown.open, width, bottom=pricesdown.open, color='r')
plt.bar(pricesdown.index, pricesdown.high - pricesdown.open, width2, bottom=pricesdown.open, color='r')
plt.bar(pricesdown.index, pricesdown.low - pricesdown.close, width2, bottom=pricesdown.close, color='r')
plt.gca().set_axis_off()
plt.subplots_adjust(
top=1,
bottom=0,
right=1,
left=0,
hspace=0,
wspace=0
)
plt.margins(0, 0)
plt.savefig(file_path, bbox_inches='tight', format=file_format, dpi=72)
但是当我使用 TensorFlow decode_png 方法加载图像时,它显示隐藏轴:
image = tf.io.read_file('test.png')
image = tf.io.decode_png(image)
plt.imshow(image)
plt.show()
图片通过windows加载 图片:
使用 TensorFlow 库在 Pythin 中加载的图像:
这没有显示隐藏轴,您的图像没有第一个轴就可以正确保存。但是当您打开图像时 plt.imshow()
正在创建并显示一个新轴。在 plt.imshow(image)
之后添加 plt.axis('off')
行,它应该删除这个新轴。