【问题标题】:Use of Linear Color mapper in Bokeh在 Bokeh 中使用线性颜色映射器
【发布时间】:2019-02-20 22:23:02
【问题描述】:

我打算使用线性颜色映射器创建散点图。该数据集是流行的女性识字率和出生率数据集。

该图的 x 轴为“人均 GDP”,y 轴为“出生时的预期寿命”。除此之外(这是我遇到问题的地方),是根据“出生率”改变点的颜色。

当前代码:

#DATA MANIPULATION

# import Pandas, Bokeh, etc
import numpy as np
import pandas as pd
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.palettes import Viridis256 as palette
from bokeh.plotting import figure
from bokeh.sampledata.autompg import autompg as df
from bokeh.transform import linear_cmap

# load the data file

excel_file = '../factbook.xlsx'
#(removed url above since it is private)
factbook  = pd.read_excel(excel_file)


source = ColumnDataSource(factbook)

colormapper = linear_cmap(field_name = factbook["Birth rate"], palette=palette, low=min(factbook["Birth rate"]), high=max(factbook["Birth rate"]))


p = figure(title = "UN Factbook Bubble Visualization", 
           x_axis_label = 'GDP per capita', y_axis_label = 'Life expectancy at birth')

p.circle(x = 'GDP per capita', y = 'Life expectancy at birth', source = source, color =colormapper)

output_file("file", title="Bubble Graph")

show(p)

p.circle 行在使用颜色映射器时出现问题。我想了解如何解决这个问题。

【问题讨论】:

    标签: python visualization bokeh graph-visualization


    【解决方案1】:

    field_name 参数应提供列名。您正在提供整个数据列本身。由于您没有提供完整的可运行示例,因此无法确定测试,但大概您想要:

    linear_cmap(field_name="Birth rate", ...)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 2022-01-16
      • 2018-02-02
      相关资源
      最近更新 更多