使用plotly绘制一个散点图,利用数据可视化的概念来观察 "预算 "与 "毛值 "之间的关系。

问题描述 投票:0回答:1

用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

请帮忙 谢谢,SB

python matplotlib data-visualization scatter-plot
1个回答
0
投票

您正在做的是,您正在加载一个新的散点图。iris 数据框架。

movies = px.data.iris()

但是,没有名为 "budget", "Gross" 就像错误信息所说的那样,你必须加载一个适当的数据框架,其中包含那些列--你的数据。你必须加载一个适当的数据框架,其中包含这些列--你的数据。

movies = your_data_frame
© www.soinside.com 2019 - 2024. All rights reserved.