python怎么交换xy轴_如何在matplotlib中更改x和y轴?

本文介绍了如何在matplotlib中交换xy轴以及创建直方图。通过使用`orientation='horizontal'`可以将直方图从垂直变为水平,而`plt.gca().invert_yaxis()`则用于反转y轴。示例代码展示了从随机数据生成直方图,并分别展示标准、水平和反转y轴的直方图效果。
摘要由CSDN通过智能技术生成

代码中的内容是如何在matplotlib中启动直方图的示例。注意,您使用的是pyplot默认接口(不一定要构建自己的图形)。

因此这一行:orientation=u'vertical',

应该是:orientation=u'horizontal',

,如果你想让酒吧从左到右。但这对y轴没有帮助。要反转y轴,应使用以下命令:plt.gca().invert_yaxis()

下面的例子向您展示了如何从随机数据中构建直方图(非对称以便更容易感知修改)。第一个图是标准直方图,第二个图改变了直方图的方向;最后一个图反转了y轴。import numpy as np

import matplotlib.pyplot as plt

data = np.random.exponential(1, 100)

# Showing the first plot.

plt.hist(data, bins=10)

plt.show()

# Cleaning the plot (useful if you want to draw new shapes without closing the figure

# but quite useless for this particular example. I put it here as an example).

plt.gcf().clear()

# Showing the plot with horizontal orientation

plt.hist(data, bins=10, orientation='horizontal')

plt.show()

# Cleaning the p

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值