如何在matplotlib中切换轴?

编程入门 行业动态 更新时间:2024-10-24 20:16:49
本文介绍了如何在matplotlib中切换轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在用matplotlib绘制图形后将x轴与y轴切换?有什么简单的方法吗?预先感谢.

I like to switch x axis with y axis after plotting a graph with matplotlib? Any easy way for it? Thanks in advance.

推荐答案

我想如果你真的要更改现有图的数据:

I guess this would be a way to do it in case you really want to change data of an existing plot:

首先执行此代码以得到一个数字:

execute this code first to get a figure:

# generate a simple figure f, ax = plt.subplots() ax.plot([1,2,3,4,5], [5,6,7,8,9]) ax.set_xlim([0, 10]) ax.set_ylim([0, 10])

然后用它来切换现有行的数据

and then use this to switch the data of an existing line

# get data from first line of the plot newx = ax.lines[0].get_ydata() newy = ax.lines[0].get_xdata() # set new x- and y- data for the line ax.lines[0].set_xdata(newx) ax.lines[0].set_ydata(newy)

更多推荐

如何在matplotlib中切换轴?

本文发布于:2023-10-08 02:52:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   matplotlib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!