Eri*_*got 31 python scatter matplotlib colorbar
在Python,与Matplotlib,如何简单地做一个散点图与透明度(阿尔法<1),但与表示它们的颜色值,但具有α-= 1颜色条?
这是一个人得到的,有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()
,但这没有做任何事......
Eri*_*got 32
好吧,我找到了一种方法,看起来相对干净:(使用ColorBar
问题中的对象)
color_bar.set_alpha(1)
color_bar.draw_all()
# pylab.draw() or pyplot.draw() might be necessary
Run Code Online (Sandbox Code Playgroud)
不过要确认这是最有效的方法,这将是很棒的!:)
Ste*_*joa 11
这是一个巨大的,丑陋的黑客.但没有其他方法可行.也许其他人可以改进.
fig1 = pylab.figure()
fig2 = pylab.figure()
ax1 = fig1.add_subplot(111)
ax2 = fig2.add_subplot(111)
ax1.scatter(range(10), range(10), c=range(10), alpha=0.2)
im = ax2.scatter(range(10), range(10), c=range(10), alpha=1.0)
fig1.colorbar(im, ax=ax1)
fig1.show()
Run Code Online (Sandbox Code Playgroud)
小智 2
Joe Kington的评论是执行此操作的正确方法,因为 matplotlib 6.0 已弃用cbar.draw_all()
:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
im = ax.scatter(range(10), range(10), c=range(10), alpha=0.2)
cbar = fig.colorbar(im, ax=ax)
cbar.solids.set(alpha=1)
Run Code Online (Sandbox Code Playgroud)
弃用警告:
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()
归档时间: |
|
查看次数: |
30068 次 |
最近记录: |