我有一个看起来像这样的Panda数据框(前六行代码段;格式略有偏离):
我一直试图在plotly express的散点函数中使用此数据框。但是,当我为range_x和range_y使用关键字参数以便修改比例时,python在运行时会抱怨说
TypeError:/的不支持的操作数类型:“ str”和“ int”
有人知道此错误的解决方法吗?
我使用了plotly_express提供的示例数据帧,并使用了plotly_express.scatter(etc。)。尽管它们也编辑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'
答案 0 :(得分:0)
所以问题在于size="NodeObs"
不是引发错误的int
。