python - plotly_express scatter函数出现问题

标签 python plotly

我有一个看起来像这样的 Panda 数据框(前六行的片段;格式有点不对):

我一直在尝试在plotlyexpress的分散函数中使用这个数据框。然而,当我使用 range_x 和 range_y 的关键字参数以便我可以修改比例时,python 在运行时提示,说

类型错误:/不支持的操作数类型:“str”和“int”

有人知道解决此错误的好方法吗?

我使用了plotly_express提供的示例数据框并使用了plotly_express.scatter(等)。尽管他们还编辑了range_x和range_y kwargs,但它仍按预期工作。

为我绘制数据框的代码。结果变量是数据帧。

px.scatter(result, x="SuccEntropy", y="KL-DivergenceFromParent", animation_frame="Age", animation_group="Node",
           size="NodeObs", color="Node", hover_name="Node", 
           size_max=38, range_x=[10, 11], range_y=[0,100])

预期结果是绘制的图表,而实际结果是以下错误消息:

TypeError                                 Traceback (most recent call last)
<ipython-input-13-57a1e6d59efb> in <module>
      1 px.scatter(result, x="SuccEntropy", y="KL-DivergenceFromParent", animation_frame="Age", animation_group="Node",
      2            size="NodeObs", color="Node", hover_name="Node",
----> 3            size_max=38, range_x=[10, 11], range_y=[0,100])

C:\Anaconda3\lib\site-packages\plotly_express\_chart_types.py in scatter(data_frame, x, y, color, symbol, size, hover_name, hover_data, text, facet_row, facet_col, error_x, error_x_minus, error_y, error_y_minus, animation_frame, animation_group, category_orders, labels, color_discrete_sequence, color_discrete_map, color_continuous_scale, range_color, color_continuous_midpoint, symbol_sequence, symbol_map, opacity, size_max, marginal_x, marginal_y, trendline, trendline_color_override, log_x, log_y, range_x, range_y, render_mode, title, template, width, height)
     50     In a scatter plot, each row of `data_frame` is represented by a symbol mark in 2D space.
     51     """
---> 52     return make_figure(args=locals(), constructor=go.Scatter)
     53 
     54 

C:\Anaconda3\lib\site-packages\plotly_express\_core.py in make_figure(args, constructor, trace_patch, layout_patch)
    795     apply_default_cascade(args)
    796     trace_specs, grouped_mappings, sizeref, show_colorbar = infer_config(
--> 797         args, constructor, trace_patch
    798     )
    799     grouper = [x.grouper or one_group for x in grouped_mappings] or [one_group]

C:\Anaconda3\lib\site-packages\plotly_express\_core.py in infer_config(args, constructor, trace_patch)
    696     sizeref = 0
    697     if "size" in args and args["size"]:
--> 698         sizeref = args["data_frame"][args["size"]].max() / args["size_max"] ** 2
    699 
    700     if "color" in args:

TypeError: unsupported operand type(s) for /: 'str' and 'int'

最佳答案

所以问题是 size="NodeObs" 不是抛出错误的 int

关于python - plotly_express scatter函数出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56635167/

相关文章:

python - 从 Python 检查 HDFS 中是否存在文件

python - 使用斜杠将多个字符串连接到python中的路径

Python:如何在另一个函数中使用一个函数中的变量

python - 如何在 Python 列表中切换两个项目的位置?

R绘图显示光标坐标

javascript - 询问 3d 曲面图时如何修复或解决 plotly 事件数据 ("plotly_hover"中的明显错误

python - 如何删除plotly tools.make_subplots中的绘图边距?

python - Visual Studio 2012 中的 IronPython

python - DecisionTreeClassifier - 树的手动修剪

python - 使用 Dash 和 Plotly 的多折线图