Skip to main content
Version: Python

Create category plots

This guide shows you how to use the plot_cat method to create category plots, which display data values from different discrete categories.

Data sourcing

From a table

When data is sourced from a Deephaven table, the following syntax can be used:

.plot_cat(series_name="series_name", t, category="Category", y="Y", y_low="YLow", y_high="YHigh", by=["GroupingColumn"])

  • plot_cat is the method used to create a category plot.
  • series_name is the name of the series on the plot.
  • t is the name of the table that holds the data you want to plot.
  • category is the column in the source table with the category values.
  • y is the column in the source table with the y values.
  • y_low is a lower y error bar.
  • y_high is a higher y error bar.
  • by is a list of one or more columns that hold grouping data.
from deephaven.column import int_col, string_col
from deephaven.plot.figure import Figure
from deephaven import new_table

source = new_table(
[string_col("Categories", ["A", "B", "C"]), int_col("Values", [1, 3, 5])]
)

plot1 = (
Figure()
.plot_cat(series_name="Categories", t=source, category="Categories", y="Values")
.show()
)

Categories with shared axes

You can also compare multiple categories by creating a category plot with shared axes. In the following example, a second category plot has been added to the previous example, thereby creating bar graphs on the same chart:

from deephaven.plot.figure import Figure
from deephaven.column import int_col, string_col
from deephaven import new_table

source_one = new_table(
[string_col("Categories", ["A", "B", "C"]), int_col("Values", [1, 3, 5])]
)
source_two = new_table(
[string_col("Categories", ["A", "B", "C"]), int_col("Values", [2, 4, 6])]
)

new_plot = (
Figure()
.plot_cat(series_name="source_one", t=source_one, category="Categories", y="Values")
.plot_cat(series_name="source_two", t=source_two, category="Categories", y="Values")
.show()
)

Subsequent categories can be added to the chart by adding additional plot_cat methods to the query.

Plot styles

By default, values are presented as vertical bars. Deephaven's PlotStyle method allows you to use other styles for your plots.

In any of the examples below, you can simply use the PlotStyle class with the appropriate value (e.g., STACKED_BAR, HISTOGRAM, etc.).

Category plot with Stacked Bar

from deephaven.plot.figure import Figure
from deephaven.plot import PlotStyle
from deephaven.column import int_col, string_col
from deephaven import new_table

source_one = new_table(
[string_col("Categories", ["A", "B", "C"]), int_col("Values", [1, 3, 5])]
)
source_two = new_table(
[string_col("Categories", ["A", "B", "C"]), int_col("Values", [2, 4, 6])]
)

new_plot = (
Figure()
.axes(plot_style=PlotStyle.STACKED_BAR)
.plot_cat(
series_name="Categories1", t=source_one, category="Categories", y="Values"
)
.plot_cat(
series_name="Categories2", t=source_two, category="Categories", y="Values"
)
.show()
)