---
title: Visualizations in Databricks notebooks and SQL editor
description: Learn about creating visualizations in Databricks notebooks and the SQL editor.
canonical_url: https://docs.databricks.com/aws/en/visualizations/
---

# Visualizations in Databricks notebooks and SQL editor

Databricks has powerful, built-in tools for creating charts and visualizations directly from your data when working with notebooks or the SQL editor. This page explains how to create, edit, and manage visualizations in notebooks and the SQL editor. To view the types of visualizations you can create, see [visualization types](https://docs.databricks.com/aws/en/visualizations/visualization-types.md).

> [!NOTE]
>
> To learn about the visualization types available for AI/BI dashboards, see [AI/BI dashboard visualization types](https://docs.databricks.com/aws/en/dashboards/manage/visualizations/types.md).

## Generate a result set to visualize

To generate the result set used on this page, use the following code:

### SQL

Run the following query in the SQL editor.

```sql
USE CATALOG samples;
   SELECT
      hour(tpep_dropoff_datetime) as dropoff_hour,
      COUNT(*) AS num
   FROM samples.nyctaxi.trips
   WHERE pickup_zip in ('10001', '10002')
   GROUP BY 1;
```

### Python

Run the following code from a Python cell in a notebook.

```python
from pyspark.sql.functions import hour, col

pickupzip = '10001'  # Example value for pickupzip
df = spark.table("samples.nyctaxi.trips")
result_df = df.filter(col("pickup_zip") == pickupzip) \
              .groupBy(hour(col("tpep_dropoff_datetime")).alias("dropoff_hour")) \
              .count() \
              .withColumnRenamed("count", "num")
display(result_df)
```

## <a id="create-vis" />Create a new visualization

You can create visualizations in the same UI where the results table appears. If you're working in a notebook, you can also generate a data profile, which provide summary statistics and visual insights for DataFrames and tables. To learn more about data profiles, see [ Generate a data profile](https://docs.databricks.com/aws/en/notebooks/eda-tutorial.md#df-profile).

1. To create a visualization, click **+** above a result and select **Visualization** to open the visualization editor.

   ### SQL editor

   ![SQL Editor results table with Visualization option shown.](https://docs.databricks.com/aws/en/images/sql/add-visualization.png)

   ### Notebook

   ![Notebook results table with Visualization option shown.](https://docs.databricks.com/aws/en/images/notebooks/add-visualization.png)

2. In the **Visualization Type** drop-down, choose a type. Then, select the data to appear in the visualization.
   ![Visualization editor](https://docs.databricks.com/aws/en/images/notebooks/visualization-editor.png)

3. After making configuration choices, click **Save**.

## Remove, duplicate, or edit a visualization

To remove, duplicate, or edit a visualization or data profile, click the downward pointing arrow at the right of the tab name. You can also create a dashboard from the menu.

> [!NOTE]
>
> If the cell contains a data profile or runs a language other than SQL, the associated visualization and data profile can only be added to a notebook dashboard. For SQL cells, you'll see an additional **Add to dashboard** menu item in the drop down. See [Add a visualization to a dashboard](https://docs.databricks.com/aws/en/visualizations/index.md#add-to-dashboard).

### SQL editor

![Visualization menu options in the SQL editor.](https://docs.databricks.com/aws/en/images/sql/download-visualization-tab-delimited.png)

### Notebook

![Visualization menu options in a notebook.](https://docs.databricks.com/aws/en/images/notebooks/nb-visualization-menu.png)

You can also rename the tab by clicking directly on the name and editing the name in place.

### Edit a visualization

To edit a visualization:

1. Click the downward pointing arrow in the visualization tab. Then, click **Edit**.
2. Use the tabs in the **Visualization Editor** to access and edit different parts of the chart.

### <a id="filter" />Filter a visualization

To apply a filter on a visualization, click ![Filter icon.](https://docs.databricks.com/aws/en/images/product-icons/FilterIcon.svg) in the upper right corner and enter the filter conditions to apply.

Filter(s) applied on a visualization will also apply to the results table. Filter(s) applied on the results table will also apply to the visualization.

![Applying a filter on a visualization also filters results table.](https://docs.databricks.com/aws/en/images/visualizations/filter-visualization.gif)

### Clone a visualization

To clone a visualization, click the downward pointing arrow in the visualization tab. Then click **Duplicate**.

## <a id="aggregation" />Enable aggregation in a visualization

For bar, line, area, pie, and heatmap charts, you add aggregation directly in the visualization rather than modifying the query to add an aggregation column. This approach has the following advantages:

* You don't need to modify the code that produces the results table.
* Modifying the aggregation allows you to quickly perform scenario-based data analysis.
* The aggregation applies to the entire dataset, not just the first 64,000 rows displayed in a table.

Aggregation is available in the following visualizations:

* Line
* Bar
* Area
* Pie
* Heatmap
* Histogram

Aggregations do not support combination visualizations, such as displaying a line and bars in the same chart.

To aggregate Y-axis columns for a visualization:

1. Open the visualization editor by creating a new chart or editing an existing chart.
   If you see the message `This visualization uses an old configuration. New visualizations support aggregating data directly within the editor`, you must re-create the visualization before you can use aggregation.

2. Next to the Y-axis columns, select the aggregation type from the following for numeric types:

   * Sum (the default)
   * Average
   * Count
   * Count Distinct
   * Max
   * Min
   * Median

   Or from the following for string types:

   * Count
   * Count Distinct

3. Click **Save**. The visualization shows the number of rows that it aggregates.

In some cases, you may not want to use aggregation on Y-axis columns. To turn off aggregation, click the kebab menu ![Kebab menu icon.](https://docs.databricks.com/aws/en/images/product-icons/OverflowIcon.svg) next to **Y columns** and uncheck **Use aggregation**.

## Edit visualization colors

You can customize a visualization's colors when you create the visualization or by editing it.

1. Create or edit a visualization.
2. Click **Colors**.
3. To modify a color, click the square and select the new color by doing one of the following:
   * Click it in the color selector.
   * Enter a hex value.
4. Click anywhere outside the color selector to close it.
5. Click **Save** in the **Visualization Editor** to save the changes.

## Temporarily hide or show a series

To hide a series in a visualization, click the series in the legend. To show the series again, click it again in the legend.

To show only a single series, double-click the series in the legend. To show other series, click each one.

## Series selection

To select a specific series to analyze on a chart, use the following commands:

* Click on a single legend item to select that series
* Cmd/Ctrl + click on a legend item to select or deselect multiple series

![Series selection](https://assets.docs.databricks.com/_static/images/visualizations/series-selection.gif)

## Sorted tooltips

Use tooltips on line charts and unstacked bar charts, ordered by magnitude, for easier analysis.

![sorted tooltips](https://assets.docs.databricks.com/_static/images/visualizations/sorted-tooltips.gif)

## Zoom

For data-dense charts, zooming in on individual data points can be helpful to investigate details and to crop outliers. To zoom in a chart, click and drag on the canvas. To clear the zoom, hover over the canvas and click the **Clear zoom** button in the upper right corner of the visualization.

![zoom in to see details](https://docs.databricks.com/aws/en/images/visualizations/zoom.gif)

## Download a visualization as a PNG file

To download a visualization as a PNG file, hover over the canvas and click the download icon in the upper-right corner.

![Click download to export the visualization as a PNG file](https://docs.databricks.com/aws/en/images/visualizations/png.gif)

A png file is downloaded to your device.

## <a id="add-to-dashboard" />Add a visualization to a dashboard

1. Click the downward pointing arrow at the right of the tab name.
2. Select **Add to dashboard**. A list of available dashboard views appears, along with a menu option **Add to new dashboard**.
3. Select a dashboard or select **Add to new dashboard**. The dashboard appears, including the newly added visualization.

## Legacy visualizations

The latest version of chart visualizations is on by default. The settings in this section describe legacy visualization that you might encounter when working with an older chart or if you have the latest version turned off.

### Visualization tools

If you hover over the upper-right of a chart in the visualization editor, a Plotly toolbar appears where you can perform operations such as select, zoom, and pan.

![Plotly toolbar](https://docs.databricks.com/aws/en/images/sql/plotly-bar.png)

If you do not see the toolbar, your administrator has [disabled toolbar display](https://docs.databricks.com/aws/en/admin/workspace-settings/appearance.md).
