I'm plotting something with seaborn's regplot
. As far as I understand, it uses pyplot.scatter
behind the scenes. So I assumed that if I specify colour for scatterplot as a sequence, I would then be able to just call plt.colorbar
, but it doesn't seem to work:
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).
Why doesn't it work, and is there a way around it?
I would be fine with using size of the dots instead of colour if there was an easy way to generate a legend for the sizes
Another approach would be
The color argument to regplot applies a single color to regplot elements (this is in the seaborn documentation). To control the scatterplot, you need to pass kwargs through:
Then you get the mappable thing (the collection made by scatter) out of the AxesSubplot seaborn returns, and specify that you want a colorbar for the mappable. Note my TODO comment, if you plan to run this with other changes to the plot.