相关疑难解决方法(0)

如何将传说从情节中删除

我有一系列20个图(不是子图)可以在一个图中制作.我希望传说能够在盒子之外.同时,我不想改变轴,因为图形的大小减少了.请帮助我以下查询:

  1. 我想将情节框保留在情节区域之外.(我希望传说位于情节区域的右侧).
  2. 无论如何,我减少了图例框内文本的字体大小,因此图例框的大小会很小.

python matplotlib legend

866
推荐指数
15
解决办法
68万
查看次数

使用matplotlib面向对象的界面用seaborn绘图

我更喜欢使用matplotlibOOP风格:

f, axarr = plt.subplots(2, sharex=True)
axarr[0].plot(...)
axarr[1].plot(...)
Run Code Online (Sandbox Code Playgroud)

这样可以更轻松地跟踪多个图形和子图.

问题:如何使用seaborn这种方式?或者,如何将此示例更改为OOP样式?如何将seaborn绘图函数描述为lmplot哪个Figure或哪个Axes绘图?

python oop matplotlib seaborn

93
推荐指数
1
解决办法
6万
查看次数

如何使用seaborn factorplot更改figureize

%pylab inline

import pandas as pd
import numpy as np
import matplotlib as mpl
import seaborn as sns

typessns = pd.DataFrame.from_csv('C:/data/testesns.csv', index_col=False, sep=';')

mpl.rc("figure", figsize=(45, 10))
sns.factorplot("MONTH", "VALUE", hue="REGION", data=typessns, kind="box", palette="OrRd");
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我总是得到一个小尺寸的数字,无论我在figsize指定的大小...如何解决它?

matplotlib seaborn

46
推荐指数
4
解决办法
5万
查看次数

在seaborn tsplot中将图例移到图外

我想创建一个时间序列图,使用seaborn.tsplot类似于此示例中的tsplot文档,但图例移到右侧,图中.

例

基于seaborn的timeseries.py中的 339-340行,看起来seaborn.tsplot目前不允许直接控制图例放置:

    if legend:
        ax.legend(loc=0, title=legend_name)
Run Code Online (Sandbox Code Playgroud)

是否有matplotlib解决方法?我正在使用seaborn 0.6-dev.

matplotlib seaborn

37
推荐指数
5
解决办法
4万
查看次数

编辑seaborn传奇

在Python中使用数据框和此代码,我能够创建一个图:

g = sns.lmplot('credibility', 'percentWatched', data=data, hue = 'millennial', markers = ["+", "."], x_jitter = True, y_jitter = True, size=5)
g.set(xlabel = 'Credibility Ranking\n ? Low       High  ?', ylabel = 'Percent of Video Watched [%]')
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但是有传说说"+ 0"和".1"对读者来说并不是很有帮助.如何编辑图例的标签?理想情况下,它不是说"千禧一代",而是说"一代"和"+千禧一代"."老一代"

python matplotlib legend seaborn

35
推荐指数
2
解决办法
5万
查看次数

AttributeError:seaborn中的未知属性图例

seaborn stripplot具有允许的功能hue.

使用https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.stripplot.html中的示例

import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.stripplot(x=tips["total_bill"])
ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在这种情况下,图例非常小,每天显示不同的色调.但是,我想删除传说.

通常,一个包括参数legend=False.但是,对于stripplot,这似乎输出属性错误:

AttributeError: Unknown property legend
Run Code Online (Sandbox Code Playgroud)

可以删除传说stripplots吗?如果是这样,那怎么做呢?

python matplotlib legend pandas seaborn

18
推荐指数
1
解决办法
1万
查看次数

从 Seaborn 线图中移动和删除图例

我正在尝试从 Seaborn 的线图中完全删除图例。2x2 子图中包含三个线图,每个线图的调用方式如下:

g = sns.lineplot(data=df, dashes=False, ax=axs[0,1])

更具体地说,我想删除三个线图中每一个中的图例,然后使用 2x2 图中的第四个区域来显示图例。任何建议表示赞赏!

matplotlib seaborn

7
推荐指数
1
解决办法
2万
查看次数

如何在seaborn.objects API中移动图例位置

seaborn.objects我正在使用v0.12.0 中提供的新API。所有示例均未显示如何移动图例位置。例如,将图例移至底部。有没有办法做到这一点?

使用, 如本答案sns.move_legend所示会产生.TypeError

import seaborn as sns
import seaborn.objects as so

healthexp = sns.load_dataset('healthexp')

p = so.Plot(healthexp, "Year", "Spending_USD", color="Country")
p.add(so.Line())
sns.move_legend(p, "upper left", bbox_to_anchor=(.55, .45), title='Species')
Run Code Online (Sandbox Code Playgroud)

追溯

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [24], in <cell line: 3>()
      1 p = so.Plot(healthexp, "Year", "Spending_USD", color="Country")
      2 p.add(so.Line())
----> 3 sns.move_legend(p, "upper left", bbox_to_anchor=(.55, .45), title='Species')

File ~\anaconda3\envs\py10\lib\site-packages\seaborn\utils.py:444, in move_legend(obj, loc, **kwargs)
    442 else:
    443     err = "`obj` must …
Run Code Online (Sandbox Code Playgroud)

python legend-properties seaborn seaborn-0.12.x

6
推荐指数
0
解决办法
714
查看次数

如何从seaborn JointGrid或jointplot中移动或删除图例

如何去掉剧情中的图例seaborn.JoingGrid

参考代码如下:

import matplotlib.pyplot as plt
import seaborn as sns

penguins = sns.load_dataset("penguins")

g = sns.JointGrid(data=penguins, x="bill_length_mm", y="bill_depth_mm", hue="species")
g.plot_joint(sns.scatterplot)
sns.boxplot(data=penguins, x=g.hue, y=g.y, ax=g.ax_marg_y)
sns.boxplot(data=penguins, y=g.hue, x=g.x, ax=g.ax_marg_x)

plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我尝试使用以下已知适用于其他seaborn地块的方法,但在jointplot上失败了:

plt.legend([],[], frameon=False)
g._legend.remove()
Run Code Online (Sandbox Code Playgroud)

python legend seaborn jointplot jointgrid

5
推荐指数
1
解决办法
2000
查看次数

如何将图例移动到海图散点图之外?

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
sns.set(style="darkgrid")

g = sns.scatterplot(x="Area", y="Rent/Sqft", hue="region", style="availability", data=df)
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我得到以下图。

在此处输入图片说明

我想将图例移出情节。我用谷歌搜索并尝试了以下

g.legend(loc='right', bbox_to_anchor=(1.25, 0.5), ncol=1)
plt.show()
Run Code Online (Sandbox Code Playgroud)

但是我没有任何输出。而且,我无法理解对象plt如何连接到我的sns对象

我正在使用Jupyter Notebook,Python 3.6和Seaborn 0.9.0。

python matplotlib scatter-plot seaborn

4
推荐指数
1
解决办法
4148
查看次数