900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > Python Seaborn或者Matplotlib作图:改变x y轴标签的字体大小(xlabel ylabel)

Python Seaborn或者Matplotlib作图:改变x y轴标签的字体大小(xlabel ylabel)

时间:2020-01-28 01:42:16

相关推荐

Python Seaborn或者Matplotlib作图:改变x y轴标签的字体大小(xlabel ylabel)

文章目录

前言Seaborn作图matplotlib作图小结参考文献

前言

创作开始时间:3月31日15:31:42

如题。给出在seaborn或者matplotlib作图这2种情况下的解决方案。

Seaborn作图

import seaborn as sns# sns.histplot会返回一个matplotlib.axes.Axes实例,基于此可以对当前正在绘制的图像进行操作ax1 = sns.histplot(df[col_name], kde = True, bins = 100, shrink = 1, color = palette.colors[0], edgecolor = palette.colors[-1])# 调整xlabel的字体大小ax1.xaxis.label.set_size(15)# 调整ylabel的字体大小ax1.yaxis.label.set_size(15)

matplotlib作图

参考:

How do I set the figure title and axes labels font size in Matplotlib?

就给出了至少三种方法:

方法1:功能强大

import matplotlib.pyplot as pltparams = {'legend.fontsize': 'x-large','figure.figsize': (15, 5),'axes.labelsize': 'x-large','axes.titlesize':'x-large','xtick.labelsize':'x-large','ytick.labelsize':'x-large'}#params = {'axes.labelsize': 16,#'axes.titlesize': 16}plt.rcParams.update(params)

方法2:中规中矩

fig = plt.figure()plt.xlabel('xlabel', fontsize=18)plt.ylabel('ylabel', fontsize=16)

方法3:和方法2差不多

fig, ax = plt.subplots()ax.set_xlabel('xlabel', fontsize=10)ax.set_ylabel('ylabel', fontsize='medium') # relative to plt.rcParams['font.size']

小结

以上。

创作结束时间:3月31日15:46:41

参考文献

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。