【问题标题】:Plotting 2 seaborn KDE joint plots in the same row在同一行中绘制 2 个 seaborn KDE 联合图
【发布时间】:2014-09-14 23:44:34
【问题描述】:

有没有办法并排绘制两个 KDE 联合图?我已经能够显示 seaborn 可以使用这样的东西生成的几乎所有类型的图表:

power_t_series = sDF.pitch
velocity_t_series = sDF.velocity
duration_t_series = sDF.duration

figure, axes = plt.subplots(nrows=1, ncols=2)
figure.set_size_inches(20,10)
b, g = sns.color_palette("muted", 2)

sns.tsplot(power_t_series, color = b, ax=axes[0])
sns.distplot(power_t_series, color = r, ax=axes[1])

但是在指定联合图时,自上而下是显示这种性质的多个图表的唯一方法吗?这是代码和错误:

figure, axes = plt.subplots(nrows=1, ncols=2)
figure.set_size_inches(20,10)
b, g = sns.color_palette("muted", 2)

sns.jointplot(power_t_series, velocity_t_series, kind='kde', ax=axes[0])
sns.jointplot(power_t_series, duration_t_series, kind='kde', ax=axes[1])

我明白了:

      3 b, g = sns.color_palette("muted", 2)
      4 
----> 5 sns.jointplot(power_t_series, velocity_t_series, kind='kde', ax=axes[0])
      6 sns.jointplot(power_t_series, duration_t_series, kind='kde', ax=axes[1])

TypeError: jointplot() got an unexpected keyword argument 'ax' 

有什么方法可以并排绘制这种类型的图表,因为 ax 不是jointplot() 接受的参数?

【问题讨论】:

    标签: python matplotlib seaborn


    【解决方案1】:

    jointplot 是一个figure-level function,不能与其他绘图共存,但有kdeplot 函数可以将二维KDE 绘制到特定轴上。见this example

    【讨论】:

    • @mwakson 哎呀。 AttributeError: 'module' 对象没有属性 'cubehelix_palette' 我使用的是 seaborn 0.4.0
    • 链接中的漂亮示例,马克。关于风格的一个问题:当你需要两个随机向量时,为什么要调用RandomState 对象而不是直接调用np.random.randn(2,50)
    • 这让我可以为随机数生成器设定一个特定的值,这样每次构建文档时绘图都不会改变。
    • @LMNYC -- 旁注:他的名字叫迈克尔,不是马克。
    猜你喜欢
    • 2016-05-04
    • 2020-06-02
    • 2021-09-06
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-09
    相关资源
    最近更新 更多