【问题标题】:CMAP returning 'TypeError: int() argument must be a string, a bytes-like object or a number, not 'list''CMAP 返回“TypeError:int() 参数必须是字符串、类似字节的对象或数字,而不是“列表”
【发布时间】:2021-10-29 12:08:53
【问题描述】:

我最近一直在玩 Matplotlib,并创建了一个 2D 直方图热图。现在我正在尝试使用 CMAP 对其进行自定义。不幸的是,它对我不起作用,因为它总是返回 'TypeError: int() argument must be a string, a bytes-like object or a number, not 'list''。

您对如何解决此问题有任何想法吗?

x = filteredData2019['capacity']
y = filteredData2019['distance']
colors = [(0, 0.33, 0.73), (1, 0.26, 0.26)]
n_bin = [100, 20]
cmap_name = 'my_list'
cm = LinearSegmentedColormap.from_list(cmap_name, colors = colors, N = n_bin)
newcolors = nump.vstack((testColor(nump.linspace(0, 1, 128)), testColor2(nump.linspace(0, 1, 
128))))
newcmp = ListedColormap(newcolors, name='OrangeBlue')
fig = plot.hist2d(x, y, bins=(130, 130), cmap = cm, norm = colors.LogNorm(),)
plot.savefig('heatScatterDistance2019.png', dpi = 1000)

【问题讨论】:

标签: python matplotlib jupyter-notebook


【解决方案1】:

您的n_bin = [100, 20] 是一个列表,然后您将其作为N 传递:

cm = LinearSegmentedColormap.from_list(cmap_name, colors=colors, N=n_bin)

它希望N 可以变成一个整数。查看使用相似变量名的this code example,您的n_bin 应该称为n_bins,然后您为每个变量调用from_list

【讨论】:

    猜你喜欢
    • 2017-11-14
    • 2016-12-06
    • 1970-01-01
    • 2021-12-04
    • 2019-09-16
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多