使用plotly绘制散点图,以查看不同类型的“预算”与“总值”之间的关系
自定义的子任务-
子任务1.1-尝试自定义散点图,添加边缘图,如直方图、方框图或小提琴图 子任务1.2-尝试链接将鼠标悬停在数据上,并尝试探索动态选择类型的选项
我的错误代码:
#Sub task 1.1 marginal plots with an histogram
movies = px.data.iris()
fig = px.scatter(movies, x="budget", y="Gross", color="genre_1", marginal_y="rug", marginal_x="histogram")
fig
错误消息:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-23-78b585ad2937> in <module>()
1 #Sub task 1.1 marginal plots with an histogram
2 movies = px.data.iris()
----> 3 fig = px.scatter(movies, x="budget", y="Gross", color="genre_1", marginal_y="rug", marginal_x="histogram")
4 fig
~/anaconda3_420/lib/python3.5/site-packages/plotly/express/_chart_types.py in scatter(data_frame, x, y, color, symbol, size, hover_name, hover_data, custom_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)
51 In a scatter plot, each row of `data_frame` is represented by a symbol mark in 2D space.
52 """
---> 53 return make_figure(args=locals(), constructor=go.Scatter)
54
55
~/anaconda3_420/lib/python3.5/site-packages/plotly/express/_core.py in make_figure(args, constructor, trace_patch, layout_patch)
1092
1093 args, trace_specs, grouped_mappings, sizeref, show_colorbar = infer_config(
-> 1094 args, constructor, trace_patch
1095 )
1096 grouper = [x.grouper or one_group for x in grouped_mappings] or [one_group]
~/anaconda3_420/lib/python3.5/site-packages/plotly/express/_core.py in infer_config(args, constructor, trace_patch)
975 all_attrables += [group_attr]
976
--> 977 args = build_dataframe(args, all_attrables, array_attrables)
978
979 attrs = [k for k in attrables if k in args]
~/anaconda3_420/lib/python3.5/site-packages/plotly/express/_core.py in build_dataframe(args, attrables, array_attrables)
897 "\n To use the index, pass it in directly as `df.index`."
898 )
--> 899 raise ValueError(err_msg)
900 if length and len(df_input[argument]) != length:
901 raise ValueError(
ValueError: Value of 'x' is not the name of a column in 'data_frame'. Expected one of ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species', 'species_id'] but received: budget
谢谢你,某人
您所做的是加载
iris
数据帧:但是,正如错误消息所说,没有名为
"budget", "Gross"
的列。您必须加载包含您的数据列的适当数据框相关问题 更多 >
编程相关推荐