2017-12-12 7 views
1

matplotlib_vennで作成されたvenn図のサブプロットを作成しています。matplotlibサブプロットの複数のタイトルを設定する

Subplots missing top-right title

お知らせ右上のプロット上の欠落タイトル:ここで私が作ってるんだプロットです。これは、私がax.set_titleを呼び出すたびに、既存のサブプロットタイトルを置き換えるためです。このプロットを作成するためのコードは以下のとおりであった:

oadoi_colors = ['all', 'closed', 'closed + green', 'bronze', 'green', 'hybrid', 'gold'] 
collections = ['Combined', 'Crossref', 'Unpaywall', 'Web of Science'] 
figure, axes = matplotlib.pyplot.subplots(nrows=len(oadoi_colors), ncols=len(collections), figsize=(2.7 * len(collections), 2.7 * len(oadoi_colors))) 
subplot_label_rectprops = {'facecolor': '#fef2e2', 'boxstyle': 'round'} 

for (oadoi_color, collection), df in coverage_df.groupby(['oadoi_color', 'collection']): 
    i = oadoi_colors.index(oadoi_color) 
    j = collections.index(collection) 
    ax = axes[i, j] 
    venn_plotter(df, ax=ax) 
    if i == 0: 
     text = ax.set_title(collection, loc='center', y=1.1) 
     text.set_bbox(subplot_label_rectprops) 
     # Top-right subplot cannot titled twice: https://stackoverflow.com/questions/36602347 
    if j == len(collections) - 1: 
     text = ax.set_title(oadoi_color.title(), x=1.1, y=0.5, verticalalignment='center', rotation=270) 
     text.set_bbox(subplot_label_rectprops) 

venn_plottermatplotlib_venn.venn3_unweightedを呼び出す関数です。 dfは、データのpandas.DataFrameです。

matplotlib title demoでは、複数のタイトルを設定できるようですが、サブプロットでこれを行う方法を理解できません。

を使用することを示唆するanswer to a similar questionがあります。しかし、イザベルを設定してもこれらのグラフには影響しません。

答えて

2

問題は、軸の各サブプロットには1つのタイトルしかないことです。 set_titleをもう一度呼び出すと、最初のタイトルが置き換えられます。
タイトルとテキストの違いはあまりありません。したがって、列のタイトルと行のテキストを使用することができます。

import matplotlib.pyplot as plt 

fig, axes = plt.subplots(3,3) 
for i in range(3): 
    for j in range(3): 
     ax = axes[i,j] 
     if i == 0: 
      title = ax.set_title("column title", loc='center', y=1.1) 
     if j == 2: 
      text = ax.text(1.1,0.5,"row title", size=12, 
          verticalalignment='center', rotation=270) 

plt.show() 

enter image description here

関連する問題