Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

How to set a common title for all the axes in a column of subfigures?

$
0
0

I'm trying to set a common title for the axes of the same column.

In the example below, we should have the ids titles only once and they should be placed at the very top of each column.

I can't figure it out. Can you guys show me how to do that ?

enter image description here

Here is my code :

import matplotlib.pyplot as pltcategories = ["category1", "category2", "category3"]ids = ["id1", "id2"]data = [    [{"A": 1, "B": 2, "C": 3}, {"D": 4, "E": 5, "F": 6}],    [{"G": 7, "H": 8, "I": 9}, {"J": 10, "K": 11, "L": 12}],    [{"M": 13, "N": 14, "O": 15}, {"P": 16, "Q": 17, "R": 18}],]fig = plt.figure(figsize=(15, 6))subfigs = fig.subfigures(len(categories), 1)for category, subfig, data_row in zip(categories, subfigs.flat, data):    _ = subfig.supylabel(t=category, x=0.09)    axs = subfig.subplots(1, len(ids))    for id, ax, data_dict in zip(ids, axs.flat, data_row):        _ = ax.set(title=id)        _ = ax.bar(data_dict.keys(), data_dict.values())plt.show()

Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>