【发布时间】:2019-03-23 01:54:34
【问题描述】:
我有一个带状图,我在其中使用分箱数据为数据点着色。我想显示一个彩条,而不是图例。我看过很多例子,但我一直不知道如何将它与 Seaborn Stripplot(和我的数据集)一起使用。
我有一个数据框 dfBalance,它在 Balance 列中有数字数据,在 Parameter 列中有不同的类别。它还包含时间列中的时间,我用它来为数据点着色
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame([[40, 'A',65], [-10, 'A',125], [60, 'B',65], [5, 'B',135], [8, 'B',205], [14, 'B',335]], columns=['Balance', 'Parameter', 'Time'])
bin = np.arange(0,max(df['Time']),60)
df['bin'] = pd.cut(abs(df['Time']),bin,precision=0)
plt.figure()
cpal=sns.color_palette('cmo.balance',n_colors=28,desat=0.8)
plt.style.use("seaborn-dark")
ax = sns.stripplot(x='Balance', y='Parameter', data=df, jitter=0.15, edgecolor='none', alpha=0.4, size=4, hue='bin', palette=cpal)
sns.despine()
ax.set_xlim([-45,45])
plt.title("L/R Balance")
plt.xlabel("Balance % L/R")
plt.ylabel("Parameter")
sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 2.5})
plt.legend(loc=1)
plt.show()
有没有办法用颜色条代替图例?
【问题讨论】:
-
@BoboDarph 不幸的是,他们没有使用可以传递给 colorbar() 的绘图(pcolor 和 imshow)。但是,我无法通过脱衣舞。当我这样做时,我得到 AttributeError: 'AxesSubplot' object has no attribute 'autoscale_None'
-
这同样适用于 imshow,所以不确定这将如何适用于 stripplot?
-
如果您提供Minimal, Complete, and Verifiable example 会更容易帮助您。请提供模型数据。具体请参考How to make good reproducible pandas examples。至少,请按原样展示您的情节图像。
标签: python matplotlib seaborn colorbar