python - 左右翻转 Plotly 水平直方图

标签 python plotly

我制作了一个水平直方图,如下图右侧所示。这可以使用 matplotlib 的 hist() 函数中的 orientation 关键字来完成,如下面的代码所示,它生成了以下图表。

enter image description here

import numpy as np
import matplotlib.pyplot as plt

#generate some data
data = np.random.normal(size=100)

#define the plot
fig, ax = plt.subplots()

#plot the data as a histogram
ax.hist(data, orientation=u'horizontal')

#move ticks to the right
ax.yaxis.tick_right()

plt.show()

是否可以翻转 x 轴,使条形底部位于右侧,而条形向左延伸,如下图中的左手图所示?

enter image description here

最佳答案

答案很简单,就是反转您希望镜像的轴的轴限制顺序。在这种特殊情况下,可以像这样达到预期的结果:

import numpy as np
import matplotlib.pyplot as plt

#generate some data
data = np.random.normal(size=100)

#define the plot
fig, ax = plt.subplots()

#plot the data as a histogram
ax.hist(data, orientation=u'horizontal')

#invert the order of x-axis values
ax.set_xlim(ax.get_xlim()[::-1])

#move ticks to the right
ax.yaxis.tick_right()

plt.show()

关于python - 左右翻转 Plotly 水平直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38799469/

相关文章:

python - 使用 unittest.mock.patch 测试 aiohttp 客户端

python - Jupyter Notebook 中未返回 Plotly 表

python - python调用存储过程时字符串值不正确警告

python - 具有多个数据库的 Django 接口(interface)(但不迁移)

python - 重定向到破折号中的 url

r - 如何在plotly中为3D绘图的轴标签添加上标或下标?

r - 如何将文本添加到 r 中的绘图箱线图中

python - 如何在价格图表上自动调整 plotly Y 范围

python - 通过 Excel 制作 CSV 在第一列名称前面给了我 ''

python - python中的lstrip函数