如何获取没有填充的联合图标记

matplotlib.pyplot.scatter()有一个facecolors=None参数将使数据点看起来内部是空心的。如何获得相同的外观seaborn.jointplot()

在早期版本的seaborn中也发现了相同的论点,但由于某种原因在最新版本(0.11)中被删除。


慕田峪9158850
浏览 81回答 2
2回答

浮云间

由于seaborn是 的高级 API matplotlib,因此这似乎反映了 中的功能matplotlib根据JointGrid 文档中的示例,参数为fc。要使用fc,ec也应该使用。指定fc='none',而不指定ec,将导致空白标记。fc: facecolor, ec: edgecolor'None'两者'none'都有效,但不是None。测试于python 3.11.3, matplotlib 3.7.1,seaborn 0.12.2import seaborn as sns# load datadf = sns.load_dataset("penguins", cache=False)# plotg = sns.jointplot(data=df, x="bill_length_mm", y="bill_depth_mm",                  ec="purple", fc="none", color='purple')当hue用于 时seaborn v0.12,fc=似乎不起作用。import seaborn as snsimport matplotlib as mpl# load datadf = sns.load_dataset("penguins")# create a palette dict with a known color_palettespecies = df.species.unique()palette = dict(zip(species, sns.color_palette(palette='crest', n_colors=len(species))))# ec requires a single value or a list of valuesec = df.species.map(palette)# plotg = sns.jointplot(data=df, x="bill_length_mm", y="bill_depth_mm", ec=ec, hue='species', palette=palette, linewidth=1)# get the join axes; not the marginsax_joint = g.ax_joint# iterate throught axes childrenfor c in ax_joint.get_children():    # set the facecolor to none    if type(c) == mpl.collections.PathCollection:            c.set_facecolor('none')# also change the legendkws = {"s": 70, "facecolor": "none", "linewidth": 1.5}handles, labels = zip(*[    (plt.scatter([], [], ec=color, **kws), key) for key, color in palette.items()])ax_joint.legend(handles, labels, title="cat")使用marker="$\circ$"产生这个情节。g = sns.jointplot(data=df, x="bill_length_mm", y="bill_depth_mm",  hue='species', palette=palette, marker="$\circ$", s=100)这似乎seaborn v0.12不起作用如果使用该参数,则需要不止一种颜色。但是,对于超过几种颜色的任何颜色, 通过将传递到的列中的唯一值压缩到已知的调色板,可以更轻松地创建。echue=palettehue如果使用连续调色板,指定n_colors将生成palette具有更好的颜色区分的颜色。'tab10'是默认值palette = dict(zip(df.species.unique(), sns.color_palette('tab10')))species = df.species.unique()和palette = dict(zip(species, sns.color_palette('crest', n_colors=len(species))))# plot g = sns.jointplot(data=df, x="bill_length_mm", y="bill_depth_mm",                   hue='species', ec=ec, fc="none", palette=palette)调色板'Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu''BuPu_r', 'CMRmap', 'CMRmap_r', 'Dark2', 'Dark2_r', 'GnBu', 'GnBu_r', 'Greens', 'Greens_r''Greys', 'Greys_r', 'OrRd', 'OrRd_r', 'Oranges', 'Oranges_r', 'PRGn', 'PRGn_r', 'Paired''Paired_r', 'Pastel1', 'Pastel1_r', 'Pastel2', 'Pastel2_r', 'PiYG', 'PiYG_r', 'PuBu''PuBuGn', 'PuBuGn_r', 'PuBu_r', 'PuOr', 'PuOr_r', 'PuRd', 'PuRd_r', 'Purples', 'Purples_r''RdBu', 'RdBu_r', 'RdGy', 'RdGy_r', 'RdPu', 'RdPu_r', 'RdYlBu', 'RdYlBu_r', 'RdYlGn''RdYlGn_r', 'Reds', 'Reds_r', 'Set1', 'Set1_r', 'Set2', 'Set2_r', 'Set3', 'Set3_r''Spectral', 'Spectral_r', 'Wistia', 'Wistia_r', 'YlGn', 'YlGnBu', 'YlGnBu_r', 'YlGn_r''YlOrBr', 'YlOrBr_r', 'YlOrRd', 'YlOrRd_r', 'afmhot', 'afmhot_r', 'autumn', 'autumn_r''binary', 'binary_r', 'bone', 'bone_r', 'brg', 'brg_r', 'bwr', 'bwr_r', 'cividis''cividis_r', 'cool', 'cool_r', 'coolwarm', 'coolwarm_r', 'copper', 'copper_r', 'crest''crest_r', 'cubehelix', 'cubehelix_r', 'flag', 'flag_r', 'flare', 'flare_r', 'gist_earth''gist_earth_r', 'gist_gray', 'gist_gray_r', 'gist_heat', 'gist_heat_r', 'gist_ncar''gist_ncar_r', 'gist_rainbow', 'gist_rainbow_r', 'gist_stern', 'gist_stern_r', 'gist_yarg''gist_yarg_r', 'gnuplot', 'gnuplot2', 'gnuplot2_r', 'gnuplot_r', 'gray', 'gray_r''hot', 'hot_r', 'hsv', 'hsv_r', 'icefire', 'icefire_r', 'inferno', 'inferno_r', 'jet''jet_r', 'magma', 'magma_r', 'mako', 'mako_r', 'nipy_spectral', 'nipy_spectral_r''ocean', 'ocean_r', 'pink', 'pink_r', 'plasma', 'plasma_r', 'prism', 'prism_r', 'rainbow''rainbow_r', 'rocket', 'rocket_r', 'seismic', 'seismic_r', 'spring', 'spring_r', 'summer''summer_r', 'tab10', 'tab10_r', 'tab20', 'tab20_r', 'tab20b', 'tab20b_r', 'tab20c''tab20c_r', 'terrain', 'terrain_r', 'turbo', 'turbo_r', 'twilight', 'twilight_r', 'twilight_shifted''twilight_shifted_r', 'viridis', 'viridis_r', 'vlag', 'vlag_r', 'winter', 'winter_r'

繁星coding

如果您希望能够利用该hue参数,首先,定义您的颜色图。其次,设置适当的色调并在调色板和边缘颜色参数中指定颜色图。penguins = sns.load_dataset("penguins")colormap = {"Adelie": "purple", "Chinstrap": "orange", "Gentoo": "green"}sns.jointplot(    data=penguins,    x="bill_length_mm",    y="bill_depth_mm",    hue="species",    palette=colormap,    ec=penguins["species"].map(colormap),    fc="none",)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python