Skip to content

Bar Charts

Bar charts are useful for comparing values across categories. You can also create grouped or stacked bars to compare multiple categories, and apply styles and customizations like colors, patterns, and text labels.

Writing prompts for Plotly Studio

You can create charts in Plotly Studio using natural language in different ways:

Ask a question - great for exploring your data:

Which factory produces the heaviest products?

Use a quick one-line prompt - concise and conversational:

Compare average weight by factory

Write structured detailed prompts - precise control and consistency:

Average Weight by Factory

Chart:
- Type: bar
- X: Factory location
- Y: Average weight

Data:
- Aggregation: average of weight by Factory location

Structured detailed prompts give you more control over chart type, data mappings, aggregations, and styling. Most examples on this page use this format.

Basic bar example

Example of comparing counts across categories.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>

The following example uses this prompt structure with the factory_location variable from the built-in Plotly Studio dataset:

Total Products by Factory Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products

Data:
- Aggregation: count by Factory location

Basic bar chart example

Horizontal bar charts

Create horizontal bars by setting the orientation.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>

Chart styles:
- Make the chart horizontal

The following example uses this prompt structure with the factory_location variable from the built-in Plotly Studio dataset:

Total Products by Factory Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products

Data:
- Aggregation: count by Factory location

Chart styles:
- Make the chart horizontal

Horizontal bar chart example

Grouped bar charts (side-by-side)

Create bars side-by-side to directly compare values between groups for each category.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>
- Color: <second_category>

Chart styles:
- Use grouped bars

The following example uses this prompt structure with the factory_location and delivery_location variables from the built-in Plotly Studio dataset to compare delivery destinations side-by-side:

Total Products by Factory and Delivery Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products
- Color: Delivery location

Data:
- Aggregation: count by Factory location and Delivery location

Chart styles:
- Use grouped bars

Grouped bar chart example

Stacked bar charts (bars on top of each other)

Stack bars on top of each other to show part-to-whole relationships and compare totals across categories.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>
- Color: <second_category>

Chart styles:
- Use stacked bars

The following example uses this prompt structure with the factory_location and delivery_location variables from the built-in Plotly Studio dataset to show stacked bars:

Total Products by Factory and Delivery Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products
- Color: Delivery location

Data:
- Aggregation: count by Factory location and Delivery location

Chart styles:
- Use stacked bars

Stacked bar chart example

Bar charts with text

Display values directly on the bars to make it easier to read exact numbers.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>

Chart styles:
- Show values on bars

The following example uses this prompt structure with the factory_location variable from the built-in Plotly Studio dataset to show product counts on each bar:

Total Products by Factory Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products

Data:
- Aggregation: count by Factory location

Chart styles:
- Show values on bars

Bar chart with text on bars example

Pattern fills

Use patterns like dots, stripes, or crosses on bars to differentiate categories.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>
- Color: <second_category>

Chart styles:
- Use grouped bars
- Use patterns

The following example uses this prompt structure with the factory_location and delivery_location variables from the built-in Plotly Studio dataset to add patterns to grouped bars:

Total Products by Factory and Delivery Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products
- Color: Delivery location

Data:
- Aggregation: count by Factory location and Delivery location

Chart styles:
- Use grouped bars
- Use patterns

Bar chart with pattern fills example

Multiple bar charts within one chart

Create multiple bar charts within one chart to compare different categories or patterns across groups. These charts, often known as faceted charts or small multiples, let you display separate subplots for each category side-by-side.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>
- Facet columns: <second_category>

The following example uses this prompt structure with the delivery_location and factory_location variables from the built-in Plotly Studio dataset to show separate subplots:

Total Products by Delivery Location and Factory

Chart:
- Type: bar
- X: Delivery location
- Y: Count of products
- Facet columns: Factory location

Data:
- Aggregation: count by Delivery location

Faceted bar chart example

Bar charts with custom hover text

Add additional information on hover to provide more context about the data.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>

Chart styles:
- Include <additional_info> on hover

The following example uses this prompt structure with the factory_location variable from the built-in Plotly Studio dataset to show custom hover text:

Total Products by Factory Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products

Data:
- Aggregation: count by Factory location

Chart styles:
- Include average_shipping_time on hover

Bar chart with custom hover text example

Rotated bar chart labels

Rotate x-axis labels to prevent overlapping when category names are long or numerous.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>

Chart styles:
- Rotate x-axis labels <angle> degrees

The following example uses this prompt structure with the factory_location variable from the built-in Plotly Studio dataset to rotate labels:

Total Products by Factory Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products

Data:
- Aggregation: count by Factory location

Chart styles:
- Rotate x-axis labels 45 degrees

Bar chart with rotated labels example

Customizing bar colors

Highlight a specific bar with a different color to draw attention to it.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>

Chart styles:
- Highlight <specific_value> in <color>

The following example uses this prompt structure with the factory_location variable from the built-in Plotly Studio dataset to highlight a specific bar:

Total Products by Factory Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products

Data:
- Aggregation: count by Factory location

Chart styles:
- Highlight Montreal in red

Bar chart with custom colors example

Rounded bars

Create bars with rounded corners for a softer, more modern look.

<Chart Title>

Chart:
- Type: bar
- X: <category_variable>
- Y: <numeric_variable>

Chart styles:
- Use rounded corners

The following example uses this prompt structure with the factory_location variable from the built-in Plotly Studio dataset to create bars with rounded corners:

Total Products by Factory Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products

Data:
- Aggregation: count by Factory location

Chart styles:
- Use rounded corners

Bar chart with rounded corners example

Interactive controls

Add dropdowns, sliders, and other controls to make your bar charts interactive. Controls let users filter and explore the data dynamically.

Total Products by Factory and Delivery Location

Chart:
- Type: bar
- X: Factory location
- Y: Count of products
- Color: Delivery location

Data:
- Aggregation: count by Factory location and Delivery location

Options:
- Dropdown to select delivery location (All, Montreal, Osaka, Seattle, Singapore) - Default All
- Checkbox to toggle between grouped and stacked bars - Default grouped

Prompt keywords reference

Use these keywords and phrases in your prompts to customize your bar chart.

Chart

Use a Chart: section in your prompt to define the basic structure of your bar chart, including the chart type and how variables map to visual properties.

Chart:
- Type: bar
- X: Factory location
- Y: Count of products
- Color: Delivery location
- Facet columns: Factory location

Here are some keyword suggestions to use in this section:

Keyword/Phrase Description Example
Type Specify the chart type as bar Type: bar
X The variable to show on the horizontal axis X: Factory location
Y The variable to show on the vertical axis Y: Count of products
Color Color bars by different groups or values Color: Delivery location
Pattern shape Map different pattern shapes to categories Pattern shape: Defect
Facet rows Create multiple plots stacked vertically by group Facet rows: Factory location
Facet columns Create multiple plots side-by-side by group Facet columns: Factory location

Data

Use a Data: section in your prompt to specify how to transform, filter, or aggregate your data before visualization.

Data:
- Aggregation: count by Factory location
- Computed field: Total value calculated as Price * Quantity

Here are some keyword suggestions to use in this section:

Keyword/Phrase Description Example
Aggregation Specify how to aggregate data Aggregation: count by Factory location
Computed field Create new calculated fields from existing data Computed field: Total value calculated as Price * Quantity
Filter Filter data to show only specific records Filter to show only defect = true

Options

Use an Options: section in your prompt to add interactive controls that allow users to dynamically filter, transform, and visualize data without regenerating the chart.

Options:
- Dropdown to select delivery location (All, Montreal, Osaka) - Default All
- Checkbox to toggle between grouped and stacked bars - Default grouped

Here are some keyword suggestions to use with this section. See Chart Controls for a complete list of control types and additional examples.

Keyword/Phrase Description Example
Dropdown Add a dropdown menu to filter by categories Dropdown to select delivery location (All, Montreal, Osaka) - Default All
Checkbox Add a checkbox to toggle options Checkbox to toggle between grouped and stacked bars - Default grouped

Chart styles

Use a Chart styles: section in your prompt to control the visual appearance and formatting of your bar chart.

Chart styles:
- Use custom colors: #FF5733, #33FF57
- Make the chart horizontal
- Use grouped bars
- Show values on bars

Here are some keyword suggestions to use in this section:

Keyword/Phrase Description Example
Custom colors Specify exact colors for bars Use custom colors: #FF5733, #33FF57
Highlight Highlight a specific bar with a different color Highlight Montreal in red
Horizontal orientation Flip bars to horizontal orientation Make the chart horizontal
Grouped bars Create bars side-by-side for comparison Use grouped bars
Stacked bars Stack bars on top of each other Use stacked bars
Text on bars Display values on the bars Show values on bars
Bar width Set the width of the bars Set bar width to 0.8
Rounded corners Create bars with rounded corners Use rounded corners
Patterns Use patterns like dots, stripes, or crosses on bars Use dotted pattern for Osaka
Hover text What to show when hovering over bars Show Factory location on hover
Axis labels Customize the text shown on the axes Label x-axis as "Factory"
Label y-axis as "Product Count"
Background color Set the background color of the plot Set background color to lightblue
Grid lines Show or hide grid lines on the plot Hide grid lines
Color scale Specify color scale for continuous color mapping. See built-in color scales Use Viridis color scale
Rotate axis labels Rotate x-axis labels to prevent overlapping Rotate x-axis labels 45 degrees
Sort Sort bars in ascending or descending order Sort bars descending
Opacity How see-through the bars are (0=invisible, 1=solid) Set opacity to 0.5
Axis range Set minimum and maximum values for axes Set y-axis range from 0 to 3000
Legend Control legend display and position Show legend at top right