0

Do you know how to apply different size to different part of text label?

fig, ax = plt.subplots()
ax.scatter(x, y,
           s=z / np.max(z)*900, alpha=0.5)
labels = [f'{i:s}\n{val:.2f}' for (i, val) in zip(names,z)]
texts = []
for xx, yy, text in zip(x, y, labels):
    texts.append(ax.text(xx, yy, text))

I want to set one fontsize for '{i:s}' part and other size for the rest '{val:.2f}' without TEX using.

EugenS
  • 83
  • 11
  • plt.tick_params(labelsize=14) – Shanteshwar Inde Mar 15 '19 at 05:10
  • Thank you @ShanteshwarInde Inde, but it is wrong: I want to set properties for text labels in annotation, not on the axis – EugenS Mar 15 '19 at 05:47
  • It's in general not possible to use different font sizes in a single label. But you could [use](https://stackoverflow.com/questions/28836048/python-matplotlib-multiple-font-sizes-in-one-label) [TeX](https://stackoverflow.com/questions/27848503/multiple-fontsize-in-same-label-matplotlib) indeed. Else, the [Rainbow text](https://matplotlib.org/gallery/text_labels_and_annotations/rainbow_text.html) example shows a way to mimick a single text with several labels. – ImportanceOfBeingErnest Mar 15 '19 at 11:27

0 Answers0