更改 python 中散点图上值的字体大小

问题描述 投票:0回答:2

如何更改Python中轴旁边散点图上值的字体大小

我看了很多教程,我只关注与 x 标签和 y 标签相关的教程,而不是如图所示的值大小In this image I have circled in red the part whose size I want to increase

以下是参考代码:

plt.figure(figsize=(170,50))  
sns.scatterplot(x= job_size_M.employee_residence, y= job_size_M.salary, hue= job_size_M.employee_residence, s=2000);
plt.xlabel('Countries', size = 100);
plt.ylabel('Salary', size = 100);
python scatter-plot
2个回答
1
投票

像这样上传代码时,需要在代码周围添加反引号。

```python
<code go here>
```

其次,如果您想在共享照片时得到问题的答案,则需要添加链接,如下所示。仅供以后参考。

![In this image I have circled in red the part whose size I want to increase](https://i.stack.imgur.com/L91Dc.jpg)

In this image I have circled in red the part whose size I want to increase

并修复您提到的错误

根据您在代码中的设置方式,它可能看起来如下

import matplotlib.pyplot as plt
import seaborn as sns

plt.figure(figsize=(170, 50))
sns.scatterplot(
    x=job_size_M.employee_residence,
    y=job_size_M.salary,
    hue=job_size_M.employee_residence,
    s=2000
)
plt.xlabel('Countries', size=100)
plt.ylabel('Salary', size=100)

# Increase the font size of the tick labels
plt.xticks(fontsize=50)
plt.yticks(fontsize=50)

plt.show()

还有另一种写法:

import seaborn as sns
import matplotlib.pyplot as plt

ax = sns.scatterplot(x=[1, 2, 3], y=[3, 1, 2])
ax.tick_params(axis='both', which='major', labelsize=20)
plt.show()

0
投票

您可以通过添加这段代码来更改轴旁边的值的字体大小:

# Adjust the values of 'fontsize' accordingly
plt.xticks(fontsize=100)
plt.yticks(fontsize=100)

您的最终代码应如下所示:

import matplotlib.pyplot as plt
import seaborn as sns

plt.figure(figsize=(170,50))
sns.scatterplot(
    x= job_size_M.employee_residence, 
    y= job_size_M.salary, 
    hue= job_size_M.employee_residence, 
    s=2000)
plt.xlabel('Countries', size=100)
plt.ylabel('Salary', size=100)

# Adjust the values of 'fontsize' accordingly
plt.xticks(fontsize=100)
plt.yticks(fontsize=100)

plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.