Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Seaborn增加自定义pairgrid中的标题字体大小_Python_Matplotlib_Seaborn - Fatal编程技术网

Python Seaborn增加自定义pairgrid中的标题字体大小

Python Seaborn增加自定义pairgrid中的标题字体大小,python,matplotlib,seaborn,Python,Matplotlib,Seaborn,我在seaborn中有以下情节,我使用SO帮助(主要)成功创建了该情节,但我目前陷入了必须增加图例标题字体大小的困境。你会怎么做呢? 我的绘图代码如下所示: import pandas as pd import seaborn as sns import matplotlib.pyplot as plt df = sns.load_dataset('iris') my_plot = sns.PairGrid(df) my_plot = my_plot.map_diag(sns.kdeplot

我在seaborn中有以下情节,我使用SO帮助(主要)成功创建了该情节,但我目前陷入了必须增加图例标题字体大小的困境。你会怎么做呢? 我的绘图代码如下所示:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

df = sns.load_dataset('iris')

my_plot = sns.PairGrid(df)
my_plot = my_plot.map_diag(sns.kdeplot, shade=True)
my_plot = my_plot.map_lower(sns.regplot, scatter_kws={'alpha':0.3})
my_plot.hue_vals = df["species"]
my_plot.hue_names = df["species"].unique()
my_plot.palette = sns.color_palette("Set2", len(my_plot.hue_names))
my_plot = my_plot.map_upper(sns.scatterplot).add_legend(title='Species', fontsize= 20, title_fontsize=25)

但不幸的是,这不起作用,只有图例增加了字体,而不是标题。 我走进了这个兔子洞:如果我理解正确的话,现在应该可以看到标题了。根据我在这里看到的文档:

我是不是理解错了?我不太确定我的假设,即seaborn的add_legend方法可以采用与matplotlib的legend方法相同的参数(如果我错了,请纠正我,因为我对seaborn方法继承的理解有点弱…)


对于如何使用不同于“添加图例”的方法或更注重matplotlib的方法修改图例元素的任何其他建议,我都会非常高兴。

因此,在代码中搜索“添加图例”后,我发现了以下部分:

title = self._hue_var if title is None else title
        try:
            title_size = mpl.rcParams["axes.labelsize"] * .85
        except TypeError:  # labelsize is something like "large"
            title_size = mpl.rcParams["axes.labelsize"]

        # Set default legend kwargs
        kwargs.setdefault("scatterpoints", 1)

        if self._legend_out:

            kwargs.setdefault("frameon", False)

            # Draw a full-figure legend outside the grid
            figlegend = self.fig.legend(handles, label_order, "center right",
                                        **kwargs)
            self._legend = figlegend
            figlegend.set_title(title, prop={"size": title_size})
基于我对这段代码的理解(这是有限的),我假设唯一的方法是更改
mpl.rcParams[“axes.labelsize”]
参数。这是可行的,但也会导致轴标签的大小发生变化:

import pandas as pd
import seaborn as sns
import matplotlib as mpl
import matplotlib.pyplot as plt

df = sns.load_dataset('iris')
mpl.rcParams["axes.labelsize"] = 20

my_plot = sns.PairGrid(df)
my_plot = my_plot.map_diag(sns.kdeplot, shade=True)
my_plot = my_plot.map_lower(sns.regplot, scatter_kws={'alpha':0.3})
my_plot.hue_vals = df["species"]
my_plot.hue_names = df["species"].unique()
my_plot.palette = sns.color_palette("Set2", len(my_plot.hue_names))
my_plot = my_plot.map_upper(sns.scatterplot).add_legend(title='Species', fontsize= '12')
这对我来说并不理想,因为它也会改变图表中的意外部分


根据
添加图例
获取参数
图例数据、标题、标签顺序
。所以
title\u fontsize
不是其中之一。好吧!那么字体大小是如何增加的呢?