在matplotlib中翻转图 [英] Flip a plot in matplotlib

查看:820
本文介绍了在matplotlib中翻转图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用matplotlib创建图

I am creating a plot with matplotlib

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)

我可以翻转图,使y轴反转,所有正值都为负,反之亦然吗?

Can I flip the plot, making the y-axis inverted and all positive values negative and vice versa?

我知道我可以乘以-1并使用invert_yaxis,但是我想知道是否有一个无需更改值即可翻转它的函数.

I know I can multiply by -1 and use invert_yaxis but I wonder if there is a function for flipping it without changing the values.

推荐答案

尝试以下功能:

plt.gca().invert_yaxis()

这篇关于在matplotlib中翻转图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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