我正在用 seaborn 的 regplot 绘制一些东西。据我了解,它在幕后使用 pyplot.scatter。所以我假设如果我将散点图的颜色指定为一个序列,那么我就可以只调用 plt.colorbar ,但它似乎不起作用:

sns.regplot('mapped both', 'unique; repeated at least once', wt, ci=95, logx=True, truncate=True, line_kws={"linewidth": 1, "color": "seagreen"}, scatter_kws={'c':wt['Cis/Trans'], 'cmap':'summer', 's':75})
plt.colorbar()

Traceback (most recent call last):

  File "<ipython-input-174-f2d61aff7c73>", line 2, in <module>
    plt.colorbar()

  File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 2152, in colorbar
    raise RuntimeError('No mappable was found to use for colorbar '

RuntimeError: No mappable was found to use for colorbar creation. First define a mappable such as an image (with imshow) or a contour set (with contourf).

为什么它不起作用,有没有办法解决它?

如果有一种简单的方法来生成大小的图例,我会很好地使用点的大小而不是颜色

最佳答案

另一种方法是

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

points = plt.scatter(tips["total_bill"], tips["tip"],
                     c=tips["size"], s=75, cmap="BuGn")
plt.colorbar(points)

sns.regplot("total_bill", "tip", data=tips, scatter=False, color=".1")

关于python - 带有色条的Seaborn regplot?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30353363/

10-15 10:20