1

I have an example plot like this:

import matplotlib.pyplot as plt
import numpy as np

x1 = np.linspace(0.0, 5.0, 100)
y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)

fig, ax = plt.subplots(figsize=(5, 3))
fig.subplots_adjust(bottom=0.15, left=0.2)
ax.plot(x1, y1)
ax.set_xlabel('x')
ax.set_ylabel('y')

plt.show()

enter image description here

What I want to do is make the tick labels, in best case conditionally, bold. For example, to print the tick labels 0.0 and 0.6 on the y-axis bold, the other ones medium. I know I can change the font weight of the axis labels using the fontweight argument, like:

ax.set_xlabel('x', fontweight='bold')

But I can't find anything similar for the tick labels. Could anyone help me?

satesrah
  • 93
  • 8

1 Answers1

1

Crude way of doing this is as follows

ax.get_xticklabels()[1].set_fontweight("bold")
ax.get_xticklabels()[5].set_fontweight("bold")

Here is the official documentation of all the text manipulations.

UserOnWeb
  • 98
  • 7
  • I know this is not 'conditional' but I am unable to get info regarding manipulation of `tick_label`. I had asked similar [question](https://stackoverflow.com/questions/57943725/matplotlib-setting-text-to-ticker) before but did not get any response. There are [some](https://stackoverflow.com/questions/32700935/get-xticklabels-contains-empty-text-instances) questions suggest using 'plt.draw()' first but I am still not able to achieve that. – UserOnWeb Sep 24 '19 at 13:47