pyplot反转x轴和反向表子图

时间:2015-03-03 16:39:41

标签: pandas matplotlib invert

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

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

enter image description here

1 个答案:

答案 0 :(得分:2)

我就是这样做的......

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()

哪个收益......

chart generated by the above code

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

df = df[::-1]

我们得到......

enter image description here