简体   繁体   English

Python数据可视化背景虚化

[英]python data visualization bokeh

Hello there wise programmers of the world 您好,世界各地的明智程序员

I´m 2 issues I have my dataset like this: 我有2个问题,我的数据集是这样的:

在此处输入图片说明

The first and main issue is that he is printing some weird plots, like this: 第一个也是主要的问题是他正在打印一些奇怪的图,例如:

在此处输入图片说明

Makes no sense in comparison with the original plot that I´m using as reference -> 与我用作参考的原始图相比没有任何意义->

在此处输入图片说明

The second issue is that he is printing some error messages -> 第二个问题是他正在打印一些错误消息->

ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: female_literacy [renderer: GlyphRenderer(id='1fb09ca6-67a9-47c6-a528-a01030829385', ...)]
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: female_literacy [renderer: GlyphRenderer(id='4ed4e766-485c-409a-9d61-1e0fdbd81c62', ...)]
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: femaleliteracy [renderer: GlyphRenderer(id='13f9c2a6-d8fc-49b2-909b-ddb50313f619', ...)]
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: femaleliteracy [renderer: GlyphRenderer(id='379aabbe-feee-4324-9819-6a019b615991', ...)]

My code goes like this: 我的代码是这样的:

# Import row from bokeh.layouts
from bokeh.layouts import row

df = pd.read_csv('literacy_birth_rate.csv')
df.columns = ['Country ', 'Continent', 'femaleliteracy', 'fertility', 'population']
source = ColumnDataSource(df)

# Create the first figure: p1
p1 = figure(x_axis_label='fertility (children per woman)', y_axis_label='femaleliteracy (% population)')

# Add a circle glyph to p1
p1.circle(x='fertility', y='femaleliteracy', source=source)

# Create the second figure: p2
p2 = figure(x_axis_label='population', y_axis_label='femaleliteracy (% population)')

# Add a circle glyph to p2
p2.circle(x='population',y='femaleliteracy', source=source)

# Put p1 and p2 into a horizontal row: layout
layout = row(p1,p2)

# Specify the name of the output_file and show the result
output_file('fert_row.html')
show(layout)

******edited*********** ******编辑***********

在此处输入图片说明

在此处输入图片说明

***************editing again*********************** ***************再次编辑***********************

 Import row from bokeh.layouts
from bokeh.layouts import row
from bokeh.plotting import figure

df = pd.read_csv('literacy_birth_rate.csv')
df.columns = ['Country', 'Continent', 'femaleliteracy', 'fertility', 'population']
df.dropna(inplace=True)
source = ColumnDataSource(df)

# Create the first figure: p1
p1 = figure(x_axis_label='fertility (children per woman)', y_axis_label='femaleliteracy (% population)')

# Add a circle glyph to p1
p1.circle(x='fertility', y='femaleliteracy', source=source)

# Create the second figure: p2
p2 = figure(x_axis_label='population', y_axis_label='femaleliteracy (% population)')

# Add a circle glyph to p2
p2.circle(x='population',y='femaleliteracy', source=source)

# Put p1 and p2 into a horizontal row: layout
layout = row(p1,p2)

# Specify the name of the output_file and show the result
output_file('fert_row.html')
show(layout)

I´ve used 我用过

df.femaleliteracy = df.femaleliteracy.astype(float) 
df.fertility = df.fertility.astype(float) 

For newbies it´s important to indicate pay attention to column types ... 对于新手,重要的是要注意列的类型 ...

to convert from object type to float, and now the plot is working... thanks a lot ... !!! 从对象类型转换为浮点数,现在该图可以工作了……非常感谢……!

the other problem was related to the fact that female_literacy was being used in a prior function call to the figure()... restarting the kernel solved that !!! 另一个问题与事实有关,在对female_literacy ()的先前函数调用中使用了female_literacy ...重新启动内核解决了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM