简体   繁体   English

我想交换 x 轴和 y 轴并将此图更改为水平图 python

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

相关问题 Matplotlib水平条形图,沿y轴带有x轴标签 - Matplotlib horizontal bar graph with x-axis label along y-axis python pandas:如何为折线图切换x轴和y轴 - python pandas: how to switch x-axis with y-axis for a line graph 需要固定图形的x轴和y轴,以便我可以清楚地看到表示形式 - Need to fix x-axis and y-axis for a graph so that I can clearly see the representation 堆叠条形图交换 x 轴和 y 轴 - Stacked bar chart swap x-axis and y-axis 有没有办法用 plotly 或 python 创建条形图可视化,其中 y 轴是 24 小时范围,x 轴是所有工作日? - Is there a way to create a bar graph visualization with plotly or python where the y-axis is 24hour range and x-axis is all the weekdays? matplotlib 从 x 轴而不是 y 轴绘制累积图 - matplotlib plot on cumulative graph from x-axis instead of y-axis 当 x 轴为日期且 y 轴为日志时,将文本添加到 Seaborn 图表 - Adding Text to Seaborn Graph when x-axis is dates and y-axis is logs 在一张图中绘制多条线,x 轴上以月为单位,y 轴上出现次数 - Plotting multiple lines in one graph with time in months on the x-axis, number of occurences on the y-axis 寻找创建折线图的方法,y 轴上有文字,x 轴上有相应的数字 - Looking for ways to create a line graph, with words along y-axis and numbers accordingly, on the x-axis 如何更改matlibplot中x轴和y轴的范围? - How to change the range of the x-axis and y-axis in matlibplot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM