Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Title is bold, but label is not. What to do?

I made a small reproducible program, where you will see the title in bold font, but the label in normal font:

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

observed = np.array([28, 15, 21, 23, 17, 22, 19, 19, 24, 27, 20, 21, 25, 25, 16, 20, 23])

fig, ax = plt.subplots(figsize=(4, 2))

sns.histplot(ax = ax, x = list(observed), label = "observed data") 
ax.set_title("Observed data", fontweight='bold')

ax.legend()
plt.show()

enter image description here

I tried to set the label in bold by putting the same code fontweight='bold' (after the label = term) inside the sns.histplot instruction, but this leads to an error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sns.histplot(ax = ax, x = list(observed), label = "observed data", fontweight='bold') 

Okay, I admit that it wasn’t a very smart attempt, but I don’t know how to get the label in bold, in a simple way…
Could someone help me to do so?

>Solution :

Adjust the font properties of the legend:

ax.legend(prop={"weight": "bold"})

https://matplotlib.org/3.5.0/api/_as_gen/matplotlib.pyplot.legend.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading