如何在matplotlib中切换轴? [英] How to switch axes in matplotlib?

查看:80
本文介绍了如何在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中切换轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆