增加海洋标题的字体尺寸

发布于 2025-02-08 09:06:31 字数 1251 浏览 2 评论 0原文

我使用以下功能创建了一个散点图:

def plot_all_seaborn(x,y,types,x_axis, y_axis, title):
    tuples = only_floats(x,y,types)
    x,y,types_new = zip(*tuples)
    frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
    sns.relplot(data=frame,
                x=x_axis, 
                y=y_axis, 
                hue="Model", 
                style="Model",
                s=500
                ).set(title=title)

对于此图,我想增加表的字体大小。我尝试在set> set方法中添加font_size参数,但这不起作用。我该如何放大标题?


基于此链接(对海出块的字体大小的良好控制),我尝试过:

def plot_all_seaborn(x,y,types,x_axis, y_axis, title):
    tuples = only_floats(x,y,types)
    x,y,types_new = zip(*tuples)
    frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
    b = sns.relplot(data=frame,
            x=x_axis, 
            y=y_axis, 
            hue="Model", 
            style="Model",
            s=500
            )
    b.set_title("Title",fontsize=20)
    plt.show()

但是,这返回以下错误:

attributeError:'facetGrid'对象没有属性'set_title'

I have created a scatterplot using the following function:

def plot_all_seaborn(x,y,types,x_axis, y_axis, title):
    tuples = only_floats(x,y,types)
    x,y,types_new = zip(*tuples)
    frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
    sns.relplot(data=frame,
                x=x_axis, 
                y=y_axis, 
                hue="Model", 
                style="Model",
                s=500
                ).set(title=title)

For this plot, I want to increase the font size of the table. I have tried adding a font_size parameter in the set method, but this does not work. How can I enlarge the title?


Based on this link (Fine control over the font size in Seaborn plots), I tried:

def plot_all_seaborn(x,y,types,x_axis, y_axis, title):
    tuples = only_floats(x,y,types)
    x,y,types_new = zip(*tuples)
    frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
    b = sns.relplot(data=frame,
            x=x_axis, 
            y=y_axis, 
            hue="Model", 
            style="Model",
            s=500
            )
    b.set_title("Title",fontsize=20)
    plt.show()

However, this returns the following error:

AttributeError: 'FacetGrid' object has no attribute 'set_title'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沫离伤花 2025-02-15 09:06:31

这是可行的,但是您必须将其他参数作为一个指定传递。

def plot_all_seaborn(x,y,types,x_axis, y_axis, title):
    tuples = only_floats(x,y,types)
    x,y,types_new = zip(*tuples)
    frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
    b = sns.relplot(data=frame,x=x_axis, y=y_axis)

    b.set_title("Title", {"fontsize"=20})

    plt.show()

This is doable, but you have to pass in the additional parameters as a dict.

def plot_all_seaborn(x,y,types,x_axis, y_axis, title):
    tuples = only_floats(x,y,types)
    x,y,types_new = zip(*tuples)
    frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
    b = sns.relplot(data=frame,x=x_axis, y=y_axis)

    b.set_title("Title", {"fontsize"=20})

    plt.show()
ぺ禁宫浮华殁 2025-02-15 09:06:31

我认为您可以这样取得成果;

def plot_seaborn(x,y,types,x_axis, y_axis, title):
    tuples = only_floats(x,y,types)
    x,y,types_new = zip(*tuples)
    frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
    sns.relplot(data=frame,
            x=x_axis, 
            y=y_axis, 
            hue="Model", 
            style="Model",
            s=500
            ).set_title(title, fontsize=23)

I think you can achieve your results like so;

def plot_seaborn(x,y,types,x_axis, y_axis, title):
    tuples = only_floats(x,y,types)
    x,y,types_new = zip(*tuples)
    frame = pd.DataFrame({x_axis:x,y_axis:y,'Model':types_new})
    sns.relplot(data=frame,
            x=x_axis, 
            y=y_axis, 
            hue="Model", 
            style="Model",
            s=500
            ).set_title(title, fontsize=23)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文