python - 无法从“bokeh.plotting”导入名称“Scatter”
问题描述
我正在尝试使用散景散点图来表示数据。这是我的代码:
from bokeh.plotting import Scatter, output_file, show import pandas df=pandas.Dataframe(colume["X","Y"]) df["X"]=[1,2,3,4,5,6,7] df["Y"]=[23,43,32,12,34,54,33] p=Scatter(df,x="X",y="Y", title="Day Temperature measurement", xlabel="Tempetature", ylabel="Day") output_file("File.html") show(p)
输出应如下所示: 预期输出
错误是:
ImportError Traceback (most recent call
> last) <ipython-input-14-1730ac6ad003> in <module>
> ----> 1 from bokeh.plotting import Scatter, output_file, show
> 2 import pandas
> 3
> 4 df=pandas.Dataframe(colume["X","Y"])
> 5
ImportError: 无法从 'bokeh.plotting' 导入名称 'Scatter' (C:\Users\LENOVO\Anaconda3\lib\site-packages\bokeh\plotting__init__.py)
我还发现 Scatter 现在不再维护。有什么方法可以使用它吗?另外,我必须使用任何其他 python 库来表示与 Scatter 相同的数据?
使用旧版本的 Bokeh 会解决这个问题吗?
解决方案
如果您在文档中查找“scatter”,您会发现
分散标记
要在绘图上散布圆形标记,请使用
circle()
Figure 的方法:from bokeh.plotting import figure, output_file, show # output to static HTML file output_file("line.html") p = figure(plot_width=400, plot_height=400) # add a circle renderer with a size, color, and alpha p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5) # show the results show(p)
要使用数据框,只需将和之类的列传df.X
递给df.Y
和x
args y
。
from bokeh.plotting import figure, show, output_file
import pandas as pd
df = pd.DataFrame(columns=["X","Y"])
df["X"] = [1,2,3,4,5,6,7]
df["Y"] = [23,43,32,12,34,54,33]
p = figure()
p.scatter(df.X, df.Y, marker="circle")
#from bokeh.io import output_notebook
#output_notebook()
show(p) # or output to a file...
推荐阅读
- javascript - antd表格行选择中全选复选框的自定义样式
- r - 运行混合模型时出错 - “名称”属性 [3] 必须与向量 [1] 的长度相同
- angular - 对象更新未反映在 HTML 角度上
- powershell - 使用 powershell 更新 Teamcity 参数
- python - 列表到字符串之间有一个空格?
- javascript - 使用 THREE.TextureLoader 时的语法问题
- python - Python praw没有将链接复制到剪贴板
- javascript - Angular 10:Styles.css 未加载到 Index.html
- javascript - NodeJs,Canvas UnhandledPromiseRejectionWarning:错误:不支持的图像类型
- reactjs - 一些图像显示在 React Native iOS 模拟器中,而另一些则没有?