部分透明的散点图,但带有纯色条 [英] Partially transparent scatter plot, but with a solid color bar
问题描述
在Python中,使用Matplotlib,如何简单地创建具有透明度(alpha <1)但具有代表其颜色值但alpha = 1的色条的散点图?
In Python, with Matplotlib, how to simply do a scatter plot with transparency (alpha < 1), but with a color bar that represents their color value, but has alpha = 1?
使用from pylab import *; scatter(range(10), arange(0, 100, 10), c=range(10), alpha=0.2); color_bar = colorbar()
可以得到以下内容:
Here is what one gets, with from pylab import *; scatter(range(10), arange(0, 100, 10), c=range(10), alpha=0.2); color_bar = colorbar()
:
如何使颜色条不透明?
PS :我尝试了color_bar.set_alpha(1); draw()
,但这没做任何事情……
PS: I tried color_bar.set_alpha(1); draw()
, but this did not do anything…
推荐答案
好的,我发现了一种比较干净的方法:(使用问题中的ColorBar
对象)
Alright, I found one way to do it, that looks relatively clean: (using the ColorBar
object from the question)
color_bar.set_alpha(1)
color_bar.draw_all()
# pylab.draw() or pyplot.draw() might be necessary
尽管确认这是进行过程中最可靠的方法,这将是非常棒的! :)
It would be great to get a confirmation that this is the most robust way to proceed, though! :)
这篇关于部分透明的散点图,但带有纯色条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!