# Histograms with Prompt AI

Becca Weng - August 21st, 2023

Histograms are one of the most foundational plot types for anyone doing data analysis since they convey a lot of information about numerical data very quickly. Luckily, creating histograms just got even easier and faster with Prompt. Prompt, Einblick's AI agent, can not only create basic histograms with just one sentence, but Prompt can also customize the plots instantly. In this post, we'll go through a few example histograms using the Olympics dataset from Kaggle.

athletic_events.head()

Code Output:

The full examples, with Prompts written in accompanying Markdown cells, can be found in the embedded canvas below. Simply open and fork the below canvas.

## Prompt 1: Basic Histogram

Since histograms are used for plotting the distribution of numerical variables, you can simply ask Prompt the following:

Plot the distribution of height.

NOTE: you can replace height with whatever numerical variable is in your particular dataset. Prompt will infer that you want a plot a histogram because the variable is numerical.

# PROMPT: Plot the distribution of height.

import matplotlib.pyplot as plt

# Plot the distribution of the 'Height' column from the 'athlete_events' dataframe
plt.hist(athlete_events['Height'], bins=10)

# Display the plot
plt.show()

Code Output:

This is a great plot for your own use, but certainly not something you would show to a stakeholder. There are a number of ways you may want to tweak the histogram--you may want to:

• Use a different visualization library
• Color parts of the graph differently based on a different variable
• Change the number of bins
• Alter text or legends on the plot

Einblick Prompt has you covered!

## Prompt 2: Use a specific library

To ask Prompt to utilize a specific library, all you have to do is add it to your prompt.

TIP: Don't worry about installation. In Einblick, Prompt will automatically pip install any missing libraries.

Plot the distribution of height using seaborn.
# PROMPT: Plot the distribution of height using seaborn

import seaborn as sns

# Set the style of the plots to 'whitegrid'
sns.set_style('whitegrid')

# Plot the distribution of the 'Height' column from the 'athlete_events' dataframe using seaborn
sns.histplot(athlete_events['Height'], bins=10)

# Display the plot
plt.show()

Code Output:

This plot looks a lot nicer, but we may want to make the graph more complex so we can compare different groups.

## Prompt 3: Color-coded histogram

Plot the distribution of height, color by sport.

To color-code by a categorical variable, we can just add a phrase to the end of our first prompt. Einblick Prompt will be able to process the request effectively.

# PROMPT: Plot the distribution of height, color by sport

import seaborn as sns

# Plot the distribution of the 'Height' column from the 'filtered_df' dataframe, color-coded by 'Sport'
sns.histplot(data=filtered_df, x='Height', hue='Sport', bins=10, legend=True)

# Display the plot
plt.show()

Code Output:

## Prompt 4: Change the color palette

If you want to recreate an existing chart, but change the color palette, you can ask Prompt to "Add new cells," and try the following:

Duplicate this chart but make it pastel
# PROMPT: Duplicate this chart but make it pastel

import seaborn as sns
import matplotlib.pyplot as plt

# Plot the distribution of the 'Height' column from the 'filtered_df' dataframe, color-coded by 'Sport' with a pastel color palette
sns.histplot(data=filtered_df, x='Height', hue='Sport', bins=10, palette='pastel')

# Display the plot
plt.show()

Code Output:

## Prompt 5: Change bins

Similar to the above prompt, if you want to tweak the number of bins or bin width, you can try a prompt like this:

Duplicate this chart but use 20 bins
# PROMPT: Duplicate this chart but use 20 bins
import seaborn as sns
import matplotlib.pyplot as plt

# Plot the distribution of the 'Height' column from the 'filtered_df' dataframe, color-coded by 'Sport' with 20 bins
sns.histplot(data=filtered_df, x='Height', hue='Sport', bins=20, palette='pastel', legend=True)

# Display the plot
plt.show()

Code Output:

Einblick is an AI-native data science platform that provides data teams with an agile workflow to swiftly explore data, build predictive models, and deploy data apps. Founded in 2020, Einblick was developed based on six years of research at MIT and Brown University. Einblick is funded by Amplify Partners, Flybridge, Samsung Next, Dell Technologies Capital, and Intel Capital. For more information, please visit www.einblick.ai and follow us on LinkedIn and Twitter.

## Start using Einblick

Pull all your data sources together, and build actionable insights on a single unified platform.

• All connectors
• Unlimited teammates
• All operators
###### Company
Website Data Collection