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

标签 pandas matplotlib reverse

当我反转 pyplot 中的 x 轴时,随附的表格不会受到影响。如何反转表格元素的显示?

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

enter image description here

最佳答案

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

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

关于pandas - pyplot 反转 x 轴和反转表格子图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28837123/

相关文章:

python - 动态更新Python中的图形线

javascript - 我不明白javascript中的这个array.reverse()

python - 计算每行的 "best of 4"平均值

python - 使用 pandas dataframe 进行多维计算

python - Gnuplot(或 matplotlib): create non-bar chart with categories on x-axis

android - 反向搜索栏(从右到左)颜色

python - 反转列表中行的顺序

python - 尝试使用字典和 map 转换包含特定文本的行时遇到问题

python-3.x - 如何将带有前导零的数据从 Pandas 导出到 CSV 并保留 csv 中的前导零

python - 将事件的时间序列 + 持续时间重新采样为并发事件