DEV Community

Cover image for kill it with the 3D scatter plot
anna lapushner
anna lapushner

Posted on

1

kill it with the 3D scatter plot

Image description

Image description

100% awesome. The interactive 3D scatterplot is so killer. The key to making a great scatter plot is picking 3 axis points that can be correlated AND choosing a mean/average of a manageable number of features.

I love it! Hope you do too!



# Create a killer 3d scatter plot of company revenue. The axis points are the top 10 restaurants, average order and rating
# Calculate average order value for each restaurant
avg_order_value = df.groupby('restaurant_name')['cost_of_the_order'].mean()

# Calculate average rating for each restaurant
avg_rating = df_rated.groupby('restaurant_name')['rating'].mean()

# Get top 10 restaurants by revenue
top_10_restaurants = revenue_by_restaurant.head(10).index

# Filter data for top 10 restaurants
df_top10 = df[df['restaurant_name'].isin(top_10_restaurants)]

# Create a new DataFrame for plotting
plot_df = pd.DataFrame({
    'Restaurant': top_10_restaurants,
    'Revenue': revenue_by_restaurant.loc[top_10_restaurants],
    'Average Order Value': avg_order_value.loc[top_10_restaurants],
    'Average Rating': avg_rating.loc[top_10_restaurants]
})

# Create 3D scatter plot
fig = px.scatter_3d(plot_df, x='Average Order Value', y='Average Rating', z='Revenue',
                    color='Restaurant', size_max=10, opacity=0.7)

fig.update_layout(title='Company Revenue vs. Average Order Value and Rating (Top 10 Restaurants)',
                  scene=dict(xaxis_title='Average Order Value',
                             yaxis_title='Average Rating',
                             zaxis_title='Revenue'))


Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs