导入 Python 散景散点图不起作用。无法导入 Default_Palette

importing Python Bokeh Scatter plots not working. Cannot import Default_Palette

我正在尝试从 bkcharts 导入 Scatter,但失败并出现以下错误:

ImportError: Traceback (most recent call last)
<ipython-input-5-23fcc4dbc1e0> in <module>()
----> 1 from bkcharts import Scatter, output_file, show
      2 import pandas
      3 
      4 df=pandas.DataFrame(columns=["X","Y"])
      5 df["X"]=[1,2,3,4,5]

c:\users\ellamm\appdata\local\programs\python\python36-32\lib\site-packages\bkcharts\__init__.py in <module>()
      3 
      4 # defaults and constants
----> 5 from bokeh.plotting.helpers import DEFAULT_PALETTE; DEFAULT_PALETTE
      6 
      7 # main components

ImportError: cannot import name 'DEFAULT_PALETTE'

我是 Bokeh 的维护者之一。您应该知道(正如项目 GitHub 页面上突出显示的那样)bkcharts 不再是核心 Bokeh 的一部分,更重要的是,它 完全没有维护 在此刻。没有未来的工作、修复或计划投入其中的努力,除非有人决定接管它。如果您必须使用 bkcharts,我唯一的建议是不要将 Bokeh 更新到 0.12.6,这是一起接受任何测试的最后一个版本。

但是,我真正的建议是此时根本不要使用 bkcharts,无论出于何种原因。很难用这么短的代码片段确切地知道你在追求什么,但我要说的是,核心 bokeh.plotting 可以很容易地绘制各种散点图,如果你追求更高级别的界面,那么 Holoviews 是官方认可的更高级别 API,它建立在 Bokeh 之上,有一个活跃的开发团队致力于此。

以下link可能有帮助:

https://docs.bokeh.org/en/latest/docs/user_guide/quickstart.html#getting-started

https://towardsdatascience.com/data-visualization-with-bokeh-in-python-part-one-getting-started-a11655a467d4

from bokeh.plotting import figure, output_file, show

试试这个代码:

from bokeh.plotting import figure,output_file,show

x=[1,2,3,4,5]
y=[5,6,4,5,3]

p=figure(title='Simple Example',x_axis_label='X Axis',y_axis_label='Y Axis')
p.circle(x,y)

output_file("Scatter_chart.html")

show(p)