[英]I want to swap x-axis and y-axis and change this graph to horizontal graph python
我想交换 x 轴和 y 轴并将这个图变成水平图
我的 python 代码
an_image = PIL.Image.open("static/img/t2.jpg")
gray_img = ImageOps.grayscale(an_image)
image_sequence = gray_img.getdata()
image_array = np.array(image_sequence)
with plt.style.context('dark_background'):
plt.plot(image_array[:1024], color='white' )
plt.savefig('static/img/his.png')
我不确定这是否是您想要的,但这将交换原始图形的 x 轴和 y 轴:
an_image = PIL.Image.open("static/img/t2.jpg")
gray_img = ImageOps.grayscale(an_image)
image_sequence = gray_img.getdata()
y = np.array(image_sequence)
with plt.style.context('dark_background'):
# Create the x-axis with the same size as y-axis
x = np.arange(0, 1024)
# Plot x-axis and y-axis in swapped positions
plt.plot(y[:1024], x, color='white')
plt.savefig('static/img/his.png')
如果我想将 x 轴移到顶部,我该怎么办?
只需添加
plt.gca().xaxis.tick_top()
在保存图之前。
完整代码:
an_image = PIL.Image.open("static/img/t2.jpg")
gray_img = ImageOps.grayscale(an_image)
image_sequence = gray_img.getdata()
y = np.array(image_sequence)
with plt.style.context('dark_background'):
x = np.arange(0, 1024)
plt.plot(y[:1024], x, color='white')
plt.gca().xaxis.tick_top()
plt.savefig('static/img/his.png')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.