I have been using matplotlib for all my publication-use figures, and one question is: how to I place the panel labels that is out of the box? The tutorial is shown here, with the code and result:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
for i, label in enumerate(('A', 'B', 'C', 'D')):
ax = fig.add_subplot(2,2,i+1)
ax.text(0.05, 0.95, label, transform=ax.transAxes,
fontsize=16, fontweight='bold', va='top')
plt.show()
But the panel label is only at the corner of the bounding box, not out side of the box and above the y axis label (which is the usual way), like this:
Any input would be appreciated. Thanks!
Matplotlib can display plot titles centered, flush with the left side of a set of axes, and flush with the right side of a set of axes. Automatic positioning can be turned off by manually specifying the y keyword argument for the title or setting rcParams["axes.
Often you may use subplots to display multiple plots alongside each other in Matplotlib. Unfortunately, these subplots tend to overlap each other by default. The easiest way to resolve this issue is by using the Matplotlib tight_layout() function.
Use legend() method to avoid overlapping of labels and autopct. To display the figure, use show() method.
values outside of [0, 1]
are valid.
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
for i, label in enumerate(('A', 'B', 'C', 'D')):
ax = fig.add_subplot(2,2,i+1)
ax.text(-0.1, 1.15, label, transform=ax.transAxes,
fontsize=16, fontweight='bold', va='top', ha='right')
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With