首页 > 解决方案 > “ListedColormap”类型的对象没有 len()

问题描述

我正在尝试修改此帖子中的代码

Python散点图。标记的大小和样式

给出不同的颜色图。我努力了

import circlesDrawer as cdraw
import matplotlib as mpl
from pylab import *
figure(figsize=(6,4))
ax = subplot(aspect='equal')
cmap = mpl.colors.ListedColormap(['royalblue', 'cyan',
                                  'yellow', 'orange'])
#plot a set of circle
a = [1,2,3]
x = [1,3,4]
y = [1,3,2]

out=cdraw.circles(x,y,1,c=a,alpha=0.5,fc=cmap)
colorbar()

show()

但得到错误

object of type 'ListedColormap' has no len()

我不知道如何解决这个问题。

标签: pythonmatplotlib

解决方案


您使用了错误的参数来提供您的颜色图。我想应该是

circles(x, y, 1, c=a, alpha=0.5, cmap=cmap)

假设,其他一切都设置正确。


推荐阅读