栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在熊猫多索引数据帧上绘制两个级别的x_ticklabel [重复]

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在熊猫多索引数据帧上绘制两个级别的x_ticklabel [重复]

试试下面的代码。通过为每种

level[0] index
情况创建一个子图
year
并将其用作x_label来实现。并为每个子图绘制数据。

def plot_function(x, ax):    ax = graph[x]    ax.set_xlabel(x, weight='bold')    return serotype_df.xs(x).plot(kind='bar', stacked='True', ax=ax, legend=False)n_subplots = len(serotype_df.index.levels[0])fig, axes = plt.subplots(nrows=1, ncols=n_subplots, sharey=True, figsize=(14, 8))  # width, heightgraph = dict(zip(serotype_df.index.levels[0], axes))plots = list(map(lambda x: plot_function(x, graph[x]), graph))ax.tick_params(axis='both', which='both', length=0)fig.subplots_adjust(wspace=0)plt.legend()plt.show()

如果您没有对每个子图进行太多更改,则可以始终执行以下操作:

plots = list(map(lambda x: serotype_df.xs(x).plot(kind='bar', stacked='True', ax=graph[x], legend=False).set_xlabel(x, weight='bold'), graph))

这样,您就不必创建或使用

plot_function



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/662544.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号