遍历自定义y-ticklabel和子图的标题

问题描述

我需要显示一些数据,这些数据使用Seaborn Heatmaps进行了颜色编码。我可以使用以下代码来显示它:

    import numpy as np
    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt

    # Read data
    header_list = ["region","year","value"]
    data=pd.read_csv("FINAL_HEAT_MAP.txt",delim_whitespace=True,names=header_list)
    df = pd.pivot_table(data,index=None,values='value',columns='region')

    # Create an array of variable to dispaly usig annot: here year
    year = np.asarray(data['year']).reshape(1,26)

    # Define the plot
    fig,axn = plt.subplots(ncols=1,nrows=5,sharey=True,sharex=True,figsize=(80,15))
    cbar_ax = fig.add_axes([.91,.13,.01,.75])
    # Use the heatmap function from the seaborn package
    for i,ax in enumerate(axn.flat):
    sns.heatmap(df,annot=year,annot_kws={"size": 45},fmt="",cmap='Oranges',ax=ax,cbar=i == 0,cbar_ax=None if i else cbar_ax,cbar_kws={'label': 'My Colorbar'})
    ax.tick_params(labelsize=45,rotation = 45)
    ax.set_xlabel("")
    new_ylabels = np.asarray(['a','b','c','d','e'])
    print(i,new_ylabels[i])
    ax.set_yticklabels(new_ylabels[i],rotation=0)

    #set Colorbar
    cbar_ax.yaxis.label.set_size(35)
    cbar_ax.tick_params(labelsize=30)

    #Add title to heatmap
    fig.suptitle('Heat Map',fontsize=45,x=0.15,y=0.92)
    plt.show()

这段代码给了我附带的结果。 我需要为每个子图定制标题,并在以后的阶段中为每个子图使用不同的输入数据文件。任何提示:

  • 如何修改代码以获取所需的内容?
  • 如何使代码自动化,以便我可以在终端的命令行中使用它,提示输入文件和变量名?

image_attached

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)