温馨提示×

Pandas中怎么使用Bokeh

小亿
84
2024-05-11 18:01:57
栏目: 编程语言

要在Pandas中使用Bokeh,首先需要导入Bokeh库和Pandas库。然后,可以通过Pandas数据结构(如DataFrame)创建Bokeh图表。下面是一个简单的示例代码,演示如何在Pandas中使用Bokeh创建一个简单的散点图:

import pandas as pd
from bokeh.plotting import figure, show
from bokeh.io import output_notebook

# 创建一个包含随机数据的DataFrame
data = {
    'x': [1, 2, 3, 4, 5],
    'y': [5, 4, 3, 2, 1]
}
df = pd.DataFrame(data)

# 创建一个Bokeh图表
output_notebook()
p = figure(title="Simple Scatter Plot", x_axis_label='X', y_axis_label='Y')
p.circle(df['x'], df['y'], size=10, color='navy', alpha=0.5)

# 显示图表
show(p)

通过以上代码,将在Jupyter Notebook中显示一个简单的散点图,其中x轴表示x列的值,y轴表示y列的值。您可以根据需要进一步定制图表,添加更多样式和功能。

0