无法从 'bokeh.plotting' 导入名称 'Scatter'
Cannot import name 'Scatter' from 'bokeh.plotting'
我正在尝试使用散景散点来表示数据。
这是我的代码:
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)
输出应如下所示:
Expected Output
错误是:
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: cannot import name 'Scatter' from 'bokeh.plotting'
(C:\Users\LENOVO\Anaconda3\lib\site-packages\bokeh\plotting__init__.py)
我还发现 Scatter 现在不再维护了。有什么方法可以使用吗?
另外,我必须使用任何其他 python 库来表示与 Scatter 相同的数据的替代方法?
使用旧版本的 Bokeh 可以解决这个问题吗?
如果您在文档中查找“分散”,您会发现
Scatter Markers
To scatter circle markers on a plot, use the circle()
method of 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
和 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...
Scatter
(大写 S)从未成为 bokeh.plotting
的一部分。它曾经是几年前删除的旧 bokeh.charts
API 的一部分。但是,根本不需要创建基本的散点图,因为 bokeh.plotting
中的所有字形方法(例如 circle
、square
)都是隐式散点类型函数,开头为:
from bokeh.plotting import figure, show
import pandas as pd
df = pd.DataFrame({"X" :[1,2,3,4,5,6,7],
"Y": [23,43,32,12,34,54,33]})
p = figure(x_axis_label="Tempetature", y_axis_label="Day",
title="Day Temperature measurement")
p.circle("X", "Y", size=15, source=df)
show(p)
产生:
您也可以直接将数据作为 传递给 circle
。
如果你想做更高级的东西,比如map the marker type based on a column还有一个plot.scatter
(小写s)方法在图上:
from bokeh.plotting import figure, show
from bokeh.sampledata.iris import flowers
from bokeh.transform import factor_cmap, factor_mark
SPECIES = ['setosa', 'versicolor', 'virginica']
MARKERS = ['hex', 'circle_x', 'triangle']
p = figure(title = "Iris Morphology")
p.xaxis.axis_label = 'Petal Length'
p.yaxis.axis_label = 'Sepal Width'
p.scatter("petal_length", "sepal_width", source=flowers, legend_field="species", fill_alpha=0.4, size=12,
marker=factor_mark('species', MARKERS, SPECIES),
color=factor_cmap('species', 'Category10_3', SPECIES))
show(p)
产生:
我正在尝试使用散景散点来表示数据。 这是我的代码:
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)
输出应如下所示: Expected Output
错误是:
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: cannot import name 'Scatter' from 'bokeh.plotting' (C:\Users\LENOVO\Anaconda3\lib\site-packages\bokeh\plotting__init__.py)
我还发现 Scatter 现在不再维护了。有什么方法可以使用吗? 另外,我必须使用任何其他 python 库来表示与 Scatter 相同的数据的替代方法?
使用旧版本的 Bokeh 可以解决这个问题吗?
如果您在文档中查找“分散”,您会发现
Scatter Markers
To scatter circle markers on a plot, use the
circle()
method of 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
和 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...
Scatter
(大写 S)从未成为 bokeh.plotting
的一部分。它曾经是几年前删除的旧 bokeh.charts
API 的一部分。但是,根本不需要创建基本的散点图,因为 bokeh.plotting
中的所有字形方法(例如 circle
、square
)都是隐式散点类型函数,开头为:
from bokeh.plotting import figure, show
import pandas as pd
df = pd.DataFrame({"X" :[1,2,3,4,5,6,7],
"Y": [23,43,32,12,34,54,33]})
p = figure(x_axis_label="Tempetature", y_axis_label="Day",
title="Day Temperature measurement")
p.circle("X", "Y", size=15, source=df)
show(p)
产生:
您也可以直接将数据作为 circle
。
如果你想做更高级的东西,比如map the marker type based on a column还有一个plot.scatter
(小写s)方法在图上:
from bokeh.plotting import figure, show
from bokeh.sampledata.iris import flowers
from bokeh.transform import factor_cmap, factor_mark
SPECIES = ['setosa', 'versicolor', 'virginica']
MARKERS = ['hex', 'circle_x', 'triangle']
p = figure(title = "Iris Morphology")
p.xaxis.axis_label = 'Petal Length'
p.yaxis.axis_label = 'Sepal Width'
p.scatter("petal_length", "sepal_width", source=flowers, legend_field="species", fill_alpha=0.4, size=12,
marker=factor_mark('species', MARKERS, SPECIES),
color=factor_cmap('species', 'Category10_3', SPECIES))
show(p)
产生: