ecjb
ecjb

Reputation: 5459

Change fontsize on y axis in barh plot from matplotlib

I want to change the fontsize of the lable on the y axis of a horizontal barplot (i.e. make the fontsize of "Question 1", "Question 2" bigger). I could not find the solution from the documentation of barh. Is it possible to do it. And if yes, where can the answer be found?

import matplotlib.pyplot as plt
import numpy as np
 
x = np.array(["Question 1", "Question 2", "Question 3", "Question 4"])
y = np.array([3, 8, 1, 10])
 
plt.barh(x, y)
plt.tight_layout()
plt.show()

enter image description here

Upvotes: 0

Views: 4563

Answers (1)

Corralien
Corralien

Reputation: 120469

Use plt.yticks:

import matplotlib.pyplot as plt
import numpy as np
 
x = np.array(["Question 1", "Question 2", "Question 3", "Question 4"])
y = np.array([3, 8, 1, 10])
 
plt.barh(x, y)
plt.yticks(fontsize=20)
plt.tight_layout()
plt.show()

enter image description here

Upvotes: 2

Related Questions