简体   繁体   English

如何正确排列我的数据和 plot x 轴?

[英]How do I arrange my data and plot x-axis correctly?

I have a dataframe that looks like this:我有一个看起来像这样的 dataframe:

在此处输入图像描述

If I do a simple plot:如果我做一个简单的 plot:

bdp.plot.bar(figsize=(10,6), width=0.85);

I get this result:我得到这个结果:

在此处输入图像描述

What's the correct way to create a two-tiered x-Something like this LIKE THIS:创建像这样的两层 x-Something 的正确方法是什么:

在此处输入图像描述

Assuming your data frame is named df and you don't require the year to show up, Try using假设您的数据框名为 df 并且您不需要显示年份,请尝试使用

df = df.reset_index()
df = df.set_index('Flexible working Age')

Then drop the year and plot the bar graph normally.然后正常删除年和 plot 条形图。 You can do this using a copy of the data frame as well您也可以使用数据框的副本来执行此操作

data = df.copy()

In case you want to retain the original data frame.如果您想保留原始数据框。

You can label the bars on top with the year if you want the year to be seen.如果你想看到年份,你可以 label 顶部的酒吧与年份。

Use a loop and use使用循环并使用

plt.annotate()

I don't have any of your code so I can't help you anymore.我没有你的任何代码,所以我不能再帮你了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM