Quantcast
Channel: How to align axis label to the right or top in matplotlib? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by iacob for How to align axis label to the right or top in matplotlib?

$
0
0

As of v3.3 you can now set these with the loc argument of set_xlabel and set_ylabel:

import matplotlib.pyplot as plt# Left plotoptions = ['left', 'center', 'right']fig, axs = plt.subplots(len(options), 1, constrained_layout=True)for ax, loc in zip(axs, options):    ax.plot([1, 2, 3])    ax.set_xlabel(f'xlabel loc={loc!r}', loc=loc)
# Right plotoptions = ['bottom', 'center', 'top']fig, axs = plt.subplots(1, len(options), constrained_layout=True)for ax, loc in zip(axs, options):    ax.plot([1, 2, 3])    ax.set_ylabel(f'ylabel loc={loc!r}', loc=loc)
enter image description hereenter image description here

Viewing all articles
Browse latest Browse all 4

Trending Articles



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