【问题标题】:How to get markers with no fill, from seaborn 0.11+如何获得没有填充的标记,来自 seaborn 0.11+
【发布时间】:2020-09-15 02:48:33
【问题描述】:

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

以前版本的 seaborn 中发现了相同的参数,但在最新版本 (0.11) 中由于某种原因被删除。

【问题讨论】:

    标签: python plot data-visualization seaborn


    【解决方案1】:
    • 由于seabornmatplotlib 的高级API,这似乎反映了matplotlib 中的功能
    • 根据JointGrid documentation中的示例,参数为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")
    

    【讨论】:

      【解决方案2】:

      如果您希望能够利用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",
      )
      

      【讨论】:

        猜你喜欢
        • 2021-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-25
        • 2012-06-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多