我制作了一个水平直方图,如下图的右图所示。可以使用orientation
matplotlibhist()
函数中的kwyword完成此操作,如下面的代码所示,该代码将生成以下图表。
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轴,以使条形图的底部在右侧,并且条形图向左延伸,如下面图像中的左图所示?
答案很简单,就是反转您要镜像的轴的轴限制顺序。在这种特殊情况下,可以实现所需的结果,如下所示:
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()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句