Create category plots
This guide shows you how to use the catPlot
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:
.catPlot(seriesName, source, categoryCol, valueCol).show()
catPlot
is the method used to create a category plot.seriesName
is the name (string) you want to use to identify the series on the plot itself.source
is the table that holds the data you want to plot.categoryCol
is the name of the column (as a string) to be used for the categories.valueCol
is the name of the column (as a string) to be used for the values.show
tells Deephaven to draw the plot in the console.
source = newTable(
stringCol("Categories", "A", "B", "C"),
intCol("Values", 1, 3, 5)
)
result = catPlot("Categories Plot", source, "Categories", "Values")
.chartTitle("Categories And Values")
.show()
- source
- result
Categories with shared axes
You can also compare multiple categories over the same period of time 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:
sourceOne = newTable(
stringCol("Categories", "A", "B", "C"),
intCol("Values", 1, 3, 5)
)
sourceTwo = newTable(
stringCol("Categories", "A", "B", "C"),
intCol("Values", 2, 4, 6)
)
result = catPlot("Categories Plot One", sourceOne, "Categories", "Values")
.catPlot("Categories Plot Two", sourceTwo, "Categories", "Values")
.chartTitle("Categories And Values")
.show()
- sourceOne
- sourceTwo
- result
Subsequent categories can be added to the chart by adding additional catPlot
methods to the query.
Plot styles
By default, values are presented as vertical bars. However, by using Deephaven's plotStyle
method, the data can be represented as a bar, a stacked bar, a line, an area or a stacked area.
In any of the examples below, you can simply swap out the plotStyle
argument with the appropriate name; e.g., ("Area")
, ("stacked_area")
, etc.
Category plot with Stacked Bar
sourceOne = newTable(
stringCol("Categories", "A", "B", "C"),
intCol("Values", 1, 3, 5)
)
sourceTwo = newTable(
stringCol("Categories", "A", "B", "C"),
intCol("Values", 2, 4, 6)
)
result = catPlot("Categories Plot One", sourceOne, "Categories", "Values")
.catPlot("Categories Plot Two", sourceTwo, "Categories", "Values")
.plotStyle("stacked_bar")
.chartTitle("Categories And Values")
.show()
- sourceOne
- sourceTwo
- result