Python Seaborn,更改颜色栏的字体大小
我想更改热图颜色条的字体大小 以下是我的代码:Python Seaborn,更改颜色栏的字体大小,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,我想更改热图颜色条的字体大小 以下是我的代码: import seaborn as sns import matplotlib.pyplot as plt from numpy import arange x = arange(25).reshape(5, 5) cmap = sns.diverging_palette(220, 20, sep=20, as_cmap=True) ax = sns.heatmap(x, cmap=cmap) plt.show() 我可以使用plt.tick_参
import seaborn as sns
import matplotlib.pyplot as plt
from numpy import arange
x = arange(25).reshape(5, 5)
cmap = sns.diverging_palette(220, 20, sep=20, as_cmap=True)
ax = sns.heatmap(x, cmap=cmap)
plt.show()
我可以使用plt.tick_参数(axis='both',labelsize=20)
更改勾号标签。但是,颜色栏字体大小不会更改。
有办法吗
您可以使用
seaborn.set()
方法更改字体比例,将font\u-scale
参数设置为所需的比例,请参阅seaborn中的更多内容
例如,比例为3的绘图:
import seaborn as sns
import matplotlib.pyplot as plt
from numpy import arange
# here set the scale by 3
sns.set(font_scale=3)
x = arange(25).reshape(5, 5)
cmap = sns.diverging_palette(220, 20, sep=20, as_cmap=True)
ax = sns.heatmap(x, cmap=cmap)
plt.show()
您可以与labelsize一起使用
例如,使用labelsize 20进行绘图:
import seaborn as sns
import matplotlib.pyplot as plt
from numpy import arange
x = arange(25).reshape(5, 5)
cmap = sns.diverging_palette(220, 20, sep=20, as_cmap=True)
ax = sns.heatmap(x, cmap=cmap)
# use matplotlib.colorbar.Colorbar object
cbar = ax.collections[0].colorbar
# here set the labelsize by 20
cbar.ax.tick_params(labelsize=20)
plt.show()
我参考了以下答案:-
- 如果设置以下内容,则会将图形中的所有文本增加两倍。但是,如果在之后立即将tick_参数设置为右下角,则只会增加颜色栏的字体大小
sns.set(font_scale=2)
sns.heatmap(df, vmin=0, vmax=1, center=0.5)
heatmap.tick_params(labelsize=15)
sns.set(font_scale=1)
别忘了将字体大小设置回原来的比例:)这并不能真正解决问题,因为您正在更改所有标签的字体大小…同意,但我不确定如何或甚至是否可以只更改一个标签的比例。很抱歉,如果这不能解决您的问题…我认为这应该是公认的答案,因为它显示了如何独立于其他标签大小更改颜色栏标签大小,而不是Filipe Amaral的答案。