[英]I want to swap x-axis and y-axis and change this graph to horizontal graph python
I want to swap the x-axis and the y-axis and turn this graph into a horizontal graph我想交换 x 轴和 y 轴并将这个图变成水平图
my python code我的 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')
I'm not sure if that's what you want, but this will swap x-axis and y-axis of the original graph:我不确定这是否是您想要的,但这将交换原始图形的 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')
If I want to move x-axis to the top What do I have to do?
如果我想将 x 轴移到顶部,我该怎么办?
Just add只需添加
plt.gca().xaxis.tick_top()
before saving the fig.在保存图之前。
Full code:完整代码:
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.