[英]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.