Seaborn,更改颜色条的字体大小

时间:2016-05-15 00:02:42

标签: python matplotlib seaborn

我想更改热图颜色条的字体大小。

以下是我的代码:

var
  i: Integer;
  lPath: string;
begin
  for i := 0 to ListBox1.Items.Count - 1 do
  begin
    lPath := ListBox1.Items.Strings[i];
    TTask.Create(
      procedure
      var
        lHTTP: TIdHTTP;
        IdSSL: TIdSSLIOHandlerSocketOpenSSL;
      begin
        lHTTP := TIdHTTP.Create(nil);

        TThread.Synchronize(nil,
          procedure
          begin
            Form1.Caption := 'Task Running...';
          end
        );

        try
          lHTTP.ReadTimeout := 30000;
          lHTTP.HandleRedirects := True;
          IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(lHTTP);
          IdSSL.SSLOptions.Method := sslvTLSv1;
          IdSSL.SSLOptions.Mode := sslmClient;
          lHTTP.IOHandler := IdSSL;
        Finally
          try
            lHTTP.Get('http://website.com/'+lPath, TStream(nil));
          Finally
            lHTTP.Free;
          end;
        end;

        TThread.Synchronize(nil,
          procedure
          begin
            Memo1.Lines.Add(lPath);
           end
        );

      end
    ).Start;

  end;
end;

我能够使用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() 更改刻度标签。但是,colorbar字体大小不会更改。 有没有办法做到这一点?

enter image description here

3 个答案:

答案 0 :(得分:4)

您可以使用seaborn.set()方法更改字体比例,将font_scale参数设置为您想要的比例,请参阅seaborn documentation中的详细信息。

例如,您的图表为比例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()

plot with big font scale

答案 1 :(得分:3)

您可以将matplotlib.axes.Axes.tick_params与标签大小一起使用。

例如,您的标签大小为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()

enter image description here

我参考了以下答案:
-Using matplotlib.colorbar.Colorbar object
-Setting parameter

答案 2 :(得分:-1)

如果您设置以下内容,它将使图表中的所有文本增加两倍。但是,如果您立即将 tick_params 设置为右下方,您将只剩下颜色栏的字体大小。

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)

不要忘记重新设置 font_scale :)

相关问题