pandas pyplot 反转 x 轴和反转表格子图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28837123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 23:00:35  来源:igfitidea点击:

pyplot Reverse x axis and reverse table subplot

pandasmatplotlibinvert

提问by Erik

When I reverse the x axis in pyplot the accompanying table does not get effected. How can i reverse the display of the table elements?

当我在 pyplot 中反转 x 轴时,随附的表格不会生效。如何反转表格元素的显示?

ax=ep.plot(kind='bar',table=True).invert_xaxis()

enter image description here

在此处输入图片说明

回答by Mark Graph

This is how I would do it ...

这就是我要做的...

import pandas as pd
import matplotlib.pyplot as plt 

# get the data ... note the order ...
data = [4.77, 5.52, 5.93, 6.29, 6.0, 6.95, 7.7, 9.44, 10.94, 12.35, 13.45]
df = pd.DataFrame({'data':data})

# referse the dataframe
df = df[::-1]

# ... and plot ...
ax = df.plot(kind='bar',table=True, figsize=(8,4)) # bar plots are categorical
ax.xaxis.set_visible(False) # table heading and x-labels over-printing
plt.show()

Which yields ...

哪个产生...

chart generated by the above code

上述代码生成的图表

And if we reverse it again ...

如果我们再次扭转它......

df = df[::-1]

We get ...

我们得到...

enter image description here

在此处输入图片说明