翻转Matplotlib imshow()的x和y轴 [英] Flip x and y axes for Matplotlib imshow()

查看:232
本文介绍了翻转Matplotlib imshow()的x和y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将pyplotmatplotlib结合使用,并且我想将某些数据显示为图像.当我使用imshow()时,数据将以我想查看的方式翻转.将其发送到imshow()之前,如何使用imshow()numpy数组切换x和y轴?

I'm using pyplot with matplotlib, and I would like to display some data as an image. When I use imshow() the data is flipped from the way I want to view it. How would I switch the x and y axes, either with imshow() or to the numpy array before I send it to imshow()?

(即我希望水平轴垂直)

(i.e. I want the horizontal axis to be vertical)

我尝试在imshow()命令中使用origin='upper'origin='lower',但这只是反转一个轴,而不是在它们周围切换

I've tried using origin='upper' and origin='lower' in the imshow() command, but that just reverses one axis instead of switching them around

我也尝试过在数据上使用reshape,但是顺序变得一团糟

I've also tried using reshape on the data, but the order gets all messed up

推荐答案

解决问题-

您需要先转置numpy数组,然后再将其传递给matplotlib:

You need to transpose the numpy array before passing it to matplotlib:

>>> a
array([[0, 1],
       [2, 3]])
>>> a=a.T
>>> a
array([[0, 2],
       [1, 3]])

因此,使用plt应该只是:

plt.imshow(a.T)

这篇关于翻转Matplotlib imshow()的x和y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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