部分透明的散点图,但带有纯色条
在Python中,使用Matplotlib,如何简单地绘制具有透明度(alpha < 1)的散点图,但具有代表其颜色值的颜色条,但alpha = 1?
这是使用 from pylab import *; 得到的结果分散(范围(10),范围(0,100,10),c=范围(10),alpha=0.2); color_bar = colorbar()
:
如何使颜色条不透明?
PS:我尝试了color_bar.set_alpha(1); draw()
,但这没有做任何事情......
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?
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()
:
How can the color bar be made non-transparent?
PS: I tried color_bar.set_alpha(1); draw()
, but this did not do anything…
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我找到了一种方法,看起来相对干净:(使用问题中的 ColorBar 对象)
不过,如果能够确认这是最可靠的方法,那就太好了! :)
Alright, I found one way to do it, that looks relatively clean: (using the
ColorBar
object from the question)It would be great to get a confirmation that this is the most robust way to proceed, though! :)
这是一个巨大而丑陋的黑客行为。但除此之外别无他法。也许其他人可以改进。
This is a huge, ugly hack. But no other way would work. Maybe someone else can improve.
乔·金顿的注释是执行此操作的正确方法,因为 matplotlib 6.0 已弃用
cbar.draw_all()
:弃用警告:
MatplotlibDeprecationWarning:draw_all 函数在 Matplotlib 3.6 中已弃用,并将在两个小版本后删除。使用Fig.draw_without_rendering()代替。 cbar.draw_all()
Joe Kington's comment is the correct way to do this as matplotlib 6.0 has deprecated
cbar.draw_all()
:The deprecation warning:
MatplotlibDeprecationWarning: The draw_all function was deprecated in Matplotlib 3.6 and will be removed two minor releases later. Use fig.draw_without_rendering() instead. cbar.draw_all()
这对我有用:
This worked for me: