【发布时间】:2020-09-15 02:48:33
【问题描述】:
matplotlib.pyplot.scatter() 有一个 facecolors=None 参数,它将使数据点看起来内部是空心的。如何获得与seaborn.jointplot() 相同的外观?
以前版本的 seaborn 中发现了相同的参数,但在最新版本 (0.11) 中由于某种原因被删除。
【问题讨论】:
标签: python plot data-visualization seaborn
matplotlib.pyplot.scatter() 有一个 facecolors=None 参数,它将使数据点看起来内部是空心的。如何获得与seaborn.jointplot() 相同的外观?
以前版本的 seaborn 中发现了相同的参数,但在最新版本 (0.11) 中由于某种原因被删除。
【问题讨论】:
标签: python plot data-visualization seaborn
seaborn 是matplotlib 的高级API,这似乎反映了matplotlib 中的功能
fc。要使用fc,您还应该使用ec。
fc='none',而不指定ec,将导致空白标记。'None' 和 'none' 都有效,但 None 无效。import seaborn as sns
# load data
penguins = sns.load_dataset("penguins", cache=False)
# set x and y
x, y = penguins["bill_length_mm"], penguins["bill_depth_mm"]
# plot
sns.jointplot(data=penguins, x="bill_length_mm", y="bill_depth_mm", ec="g", fc="none")
【讨论】:
如果您希望能够利用hue 参数,这里有一种构建方法可以脱离@Trenton 的回答。首先,定义您的颜色图。其次,设置适当的色调并在调色板和边缘颜色参数中指定颜色图。
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",
)
【讨论】: