简体   繁体   English

从 matplotlib 更改 barh plot 中 y 轴上的字体大小

[英]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 (ie make the fontsize of "Question 1", "Question 2" bigger).我想更改水平条形图 y 轴上标签的字体大小(即使“问题 1”、“问题 2”的字体大小更大)。 I could not find the solution from the documentation of barh .我无法从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()

在此处输入图像描述

Use plt.yticks :使用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()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM