---
title: Plot Component Formatting
---

> [!WARNING]
> Legacy documentation: This documentation applies to **Legacy Deephaven Enterprise only** and does not apply to Core+.

> [!NOTE]
> For Core+ workers, see Community Core documentation for [Plot Style](/core/docs/reference/plot/plotStyle).

Any aspect of the figure can be manipulated by calling specific methods on the respective object (e.g., figure, chart, axes, axis). Each method used must be applied to the appropriate object, as defined in the Plotting API. For example, the `figureTitle` method cannot be called in the query before the figure is created.

> [!NOTE]
> See also
> The following are representative samples for customizing various components of figures and charts created in Deephaven. For the complete list of options, refer to the [PyDocs](https://docs.deephaven.io/pydocs/code/deephaven.Plot.html) or the [Javadoc](https://docs.deephaven.io/javadoc/2026.01/com/illumon/iris/db/plot/package-summary.html).

## Plot Styles

Plot Styles are methods you can use to change the "style" of XY Series charts and Category charts. For example, an XY Series plot uses lines as a default to show the values being plotted. However, you can easily change that to a different style of chart by applying the `plotStyle` method. Arguments include the following:

- `Bar`
- `Stacked_Bar`
- `Line`
- `Area`
- `Stacked_Area`
- `Scatter`
- `Step`

> [!TIP]
> Argument capitalization does not matter.

Examples of the syntax needed when using the `plotStyle` method follow:

- `plot(series, t, "x", "y").plotStyle("Area")` - changes an XY series plot to present as an area plot instead of a line.
- `plot(series, t, "x", "y").plotStyle("Step")` - changes an XY series plot to present as a step plot instead of a line.
- `catPlot(series, t, "x", "y").plotStyle("Line")` - changes a category plot to present as a line plot instead of a column.

### Examples

- [Using Plotting Styles with XY Series Plots](./legacy-plotting.md#xy-series-with-plot-styles)
- [Using Plotting Styles with Category Plots](./legacy-plotting.md#category-charts-with-plot-styles)

## Plot Titles and Labels

### Static Chart Titles and Labels

Titles and labels are not automatically generated when plots are created in Deephaven. However, they can easily be added:

- `figureTitle("Figure 5.1")` - adds a figure title
- `chartTitle("My Chart")` - adds a chart title
- `xLabel("Time")` - adds an X axis label
- `yLabel("Dollars")` - adds a Y axis label

### Dynamic Chart Titles

As described above, the 'chartTitle' method can be used to manually add titles to the plots you create in Deephaven. However, chart titles can also be dynamically generated based on the content of the data you are plotting.

> [!NOTE]
> OneClick plots paired with an Input Filter on the web will automatically include the applied Input (e.g., "AAPL" for a plot filtered to the AAPL USym); however, the methods and further options discussed below are available in Deephaven Classic.

#### Dynamic Chart Titles Using OneClick

Dynamic chart titles can also be created using data from a table that is being filtered with an Input (OneClick) Filter. In this case, the dynamic chart title updates when the underlying source updates.

> [!NOTE]
> On the web, OneClick plot chart titles will automatically update to reflect the Input Filter applied. The methods below will work for queries run in Deephaven Classic.

```python skip-test
from deephaven import Plot

t = db.t("LearnDeephaven", "EODTrades")\
    .where("ImportDate=`2017-11-01`")

oneClickTable1 = Plot.oneClick(t, "Ticker")

inputPlot = Plot.plot("Price Trend", oneClickTable1, "EODTimestamp", "Close")\
    .chartTitle(oneClickTable1, "Ticker")
    .show()
```

```groovy
t = db.t("LearnDeephaven", "EODTrades")
    .where("ImportDate=`2017-11-01`")

oneClickTable1 = oneClick(t, "Ticker")

samplePlot = plot("Price Trend", oneClickTable1, "EODTimestamp", "Close")
    .chartTitle(oneClickTable1, "Ticker")
    .show()
```

#### Dynamic chart titles using table data

> [!NOTE]
> The table column argument for `chartTitle` is only available in Deephaven Classic (Swing).

To create a dynamic chart title using a value from the data you are plotting, the following syntax may be used:

`.chartTitle(tableName, "colName")`

For example, the following code sample will dynamically create a chart title using data from the Ticker column:

```python
from deephaven import Plot

t2 = (
    db.t("LearnDeephaven", "EODTrades")
    .where("ImportDate=`2017-11-01`")
    .where("Ticker=`CSC`")
)

dynamicTitle = (
    Plot.plot("Price Trend", t2, "EODTimestamp", "Close")
    .chartTitle(t2, "Ticker")
    .show()
)
```

```groovy
t2 = db.t("LearnDeephaven", "EODTrades").where("ImportDate=`2017-11-01`")
    .where("Ticker=`CSC`")

dynamicTitle = plot("Price Trend", t2, "EODTimestamp", "Close")
    .chartTitle(t2, "Ticker")
    .show()
```

![img](../../assets/plotting/dynamicswingplot.png)

As shown above, the source table was filtered to show only CSC as the Ticker, so the chart title was dynamically created to match that value (CSC). If the source table was subsequently filtered to show only MSFT as the Ticker value, the chart title would update to show MSFT.

#### Configuration options for Dynamic Chart titles

##### Values shown for each column

The number of values/rows shown for each column in the chart title can be configured in the following ways:

- `Plot.chartTitle.maxRowsInTitle` property: `3` rows by default, if not otherwise set in `iris-defaults.prop`; applicable to all charts.
- `maxRowsInTitle(int)` method changes the max rows for a specific chart.

Note the following when setting the `maxRowsInTitle` property:

1. If `maxRowsInTitle = 0`, only the first value from the title column will be shown.
2. If `maxRowsInTitle > 0`: If the number of values/rows in a column is more than `maxRowsInTitle`, then the values will be shown as comma-separated values followed by an ellipsis (...). Otherwise, only comma-separated values will be shown without an ellipsis.
3. If `maxRowsInTitle < 0`: All values/rows in the column will be shown in the title and separated by commas.

**Example `>0`**

```python
from deephaven import Plot

t3 = db.t("LearnDeephaven", "StockTrades").where("Date=`2017-08-25`", "Sym=`AAPL`")

title4 = (
    Plot.plot("P", t3, "Timestamp", "Last")
    .chartTitle(t3.selectDistinct("Exchange"), "Exchange")
    .maxRowsInTitle(4)
    .show()
)
```

```groovy
t3 = db.t("LearnDeephaven", "StockTrades")
    .where("Date=`2017-08-25`", "Sym=`AAPL`")

title4 = plot("P", t3, "Timestamp", "Last")
    .chartTitle(t3.selectDistinct("Exchange"), "Exchange")
    .maxRowsInTitle(4)
    .show()
```

![img](../../assets/plotting/dynamicTitle3.png)

As shown above, the first four values are shown in the title. Since the column for the title (Exchange) has 10 values (more than four), the title string has an ellipsis.

**Example `<0`**

```python
from deephaven import Plot

t3 = db.t("LearnDeephaven", "StockTrades").where("Date=`2017-08-25`", "Sym=`AAPL`")

p = (
    Plot.plot("P", t3, "Timestamp", "Last")
    .chartTitle(t3.selectDistinct("Exchange"), "Exchange")
    .maxRowsInTitle(-1)
    .show()
)
```

```groovy
t3 = db.t("LearnDeephaven", "StockTrades")
     .where("Date=`2017-08-25`", "Sym=`AAPL`")

p = plot("P", t3, "Timestamp", "Last")
     .chartTitle(t3.selectDistinct("Exchange"), "Exchange")
     .maxRowsInTitle(-1)
```

![img](../../assets/plotting/dynamicTitle4.png)

The above example shows all the values in the title column because we are passing `-1 (<0)` in `maxRowsInTitle()`.

##### Format of the title string

By default just the comma-separated values/rows according to the `maxRowsInTitle` for each column are shown in the title string. This format can be customized to include column names or any other custom text along with the values.

To include the table's column names, the following syntax is used:

`.chartTitle(boolean showColumnNamesInTitle, Table t, String... titleColumns)`

The first argument is a boolean value which determines whether to show column names in the title.

For example, the following query places column names along with the values in the chart title. As shown below, `true` has been passed as the first argument and hence the chart title will include the column names along with the values.

**Example of column names and values**

```python skip-test
from deephaven import *

t3 = db.t("LearnDeephaven", "StockTrades").where("Date=`2017-08-25`", "Sym=`AAPL`")

tAgg = t3.by(
    caf.AggCombo(
        caf.AggMin("MinTradePrice=Last"),
        caf.AggAvg("AvgTradePrice=Last"),
        caf.AggMax("MaxTradePrice=Last"),
    ),
    "Sym",
)

p = (
    Plot.plot("TradePrice", t3, "Timestamp", "Last")
    .chartTitle(True, tAgg, "Sym", "MinTradePrice", "AvgTradePrice", "MaxTradePrice")
    .show()
)
```

```groovy
t3 = db.t("LearnDeephaven", "StockTrades")
	.where("Date=`2017-08-25`", "Sym=`AAPL`")

tAgg = t3.by(AggCombo(AggMin("MinTradePrice=Last"), AggAvg("AvgTradePrice=Last"), AggMax("MaxTradePrice=Last")), "Sym")

p = plot("TradePrice", t3, "Timestamp", "Last")
    .chartTitle(true, tAgg, "Sym", "MinTradePrice", "AvgTradePrice", "MaxTradePrice")
	.show()
```

![img](../../assets/plotting/dynamicTitle5.png)

In addition to that, title format can be customized to include text along with the place holders for the column values. The basic syntax for this version of the `chartTitle` function follows:

`.chartTitle(String titleFormat, Table t, String... titleColumns)`

**Example of title format**

```python skip-test
from deephaven import *

t3 = db.t("LearnDeephaven", "StockTrades").where("Date=`2017-08-25`", "Sym=`AAPL`")

tAgg = t3.by(
    caf.AggCombo(
        caf.AggMin("MinTradePrice=Last"),
        caf.AggAvg("AvgTradePrice=Last"),
        caf.AggMax("MaxTradePrice=Last"),
    ),
    "Sym",
)

p = (
    Plot.plot("TradePrice", t3, "Timestamp", "Last")
    .chartTitle(
        "Ticker: {0}    	Min: {1}    	Max: {2}    	Avg: {3}",
        tAgg,
        "Sym",
        "MinTradePrice",
        "AvgTradePrice",
        "MaxTradePrice",
    )
    .show()
)
```

```groovy
t3 = db.t("LearnDeephaven", "StockTrades")
    .where("Date=`2017-08-25`", "Sym=`AAPL`")

tAgg = t3.by(AggCombo(AggMin("MinTradePrice=Last"), AggAvg("AvgTradePrice=Last"), AggMax("MaxTradePrice=Last")), "Sym")

p = plot("TradePrice", t3, "Timestamp", "Last").chartTitle("Ticker: {0}    	Min: {1}    	Max: {2}    	Avg: {3}", tAgg, "Sym", "MinTradePrice", "AvgTradePrice", "MaxTradePrice")
	.show()
```

![img](../../assets/plotting/dynamicTitle6.png)

#### Troubleshooting Dynamic Chart Titles for Python

<details>
<summary>Depending on the installation of the Python wheel files associated with this release, the user may find the following exceptions:</summary>

```
java.lang.RuntimeException: Error in Python interpreter:
Type: <type 'exceptions.AttributeError'>
Value: 'FigureWrapper' object has no attribute 'maxRowsInTitle'
Line: 4
Namespace: <module>
File: <string>
        at org.jpy.PyLib.executeCode(PyLib.java:-2)
        at org.jpy.PyObject.executeCode(PyObject.java:88)
        at com.illumon.iris.db.util.PythonEvaluatorJpy.evalScript(PythonEvaluatorJpy.java:47)
        at com.illumon.iris.db.util.IrisDbPythonSession.lambda$evaluate$1(IrisDbPythonSession.java:144)
        at com.illumon.util.locks.FunctionalLock.doLockedInterruptibly(FunctionalLock.java:45)
        at com.illumon.iris.db.util.IrisDbPythonSession.evaluate(IrisDbPythonSession.java:143)
        at com.illumon.iris.console.events.RemoteScriptCommandQuery.execute(RemoteScriptCommandQuery.java:94)
        at com.illumon.iris.console.events.RemoteScriptCommandQuery.execute(RemoteScriptCommandQuery.java:26)
        at com.illumon.iris.db.tables.remotequery.RemoteQueryProcessor$QueryAction.lambda$execute$0(RemoteQueryProcessor.java:1705)
        at com.illumon.util.locks.FunctionalLock.computeLockedInterruptibly(FunctionalLock.java:80)
        at com.illumon.iris.db.tables.remotequery.RemoteQueryProcessor$QueryAction.execute(RemoteQueryProcessor.java:1705)
         at com.illumon.iris.db.tables.remotequery.RemoteQueryProcessor$ClientConnectionHandler.runSyncQueryAndSendResult(RemoteQueryProcessor.java:1474)
        at com.illumon.iris.db.tables.remotequery.RemoteQueryProcessor$ClientConnectionHandler.handleCommandST(RemoteQueryProcessor.java:1374)
        at com.illumon.iris.db.tables.remotequery.RemoteQueryProcessor$ClientConnectionHandler$HandleCommandRunnable.run(RemoteQueryProcessor.java:983)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
```

</details>

The above exception indicates the Python wheel files associated with this release (a) are not installed or (b) are installed but are missing some JPY JVM flags. To eliminate this exception, you need to (a) ensure the Python wheel file associated with this release is correctly installed, and (b) pass the following JVM arguments while running your Python console:

```
-Djpy.programName=/db/VEnvs/python27/bin/python2.7`
-Djpy.pythonLib=/usr/lib64/libpython2.7.so.1.0
-Djpy.jpyLib=/db/VEnvs/python27/lib/python2.7/site-packages/jpy.so
-Djpy.jdlLib=/db/VEnvs/python27/lib/python2.7/site-packages/jdl.so
```

## Axis Formatting

### Setting Axis Ranges and Ticks

| Method                                                                            | Description                                                                                            |
| --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| `xRange(0, 100)`                                                                  | Adjusts the range of the X axis.                                                                       |
| `yMin(15.5)`                                                                      | Sets the minimum value on the Y axis.                                                                  |
| `yMax(100)`                                                                       | Sets the maximum value on the Y axis.                                                                  |
| `.plot(...).twinX().plot(...)`                                                    | Adds a shared axis. The first `.plot` argument uses the left Y axis; the second uses the right Y axis. |
| `xTickLabelAngle(45.0)`                                                           | Changes the angle of the tick labels on the X axis.                                                    |
| <ul><li>`yTicks(10)`</li><li>`xTicks(10)`</li></ul>                               | Sets gap between major ticks on the Y or X axis.                                                       |
| <ul><li>`xMinorTicksVisible(false)`</li><li>`yMinorTicksVisible(false)`</li></ul> | Turns off minor ticks on both axes.                                                                    |

### Setting Axis Time Formatting

| Method                                    | Description                                                                                                              | Formatted Examples   |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | -------------------- |
| `xFormatPattern("yyyy-MM-dd")`            | Changes the format used on the X axis to show the year, month and day.                                                   | 2017-03-08           |
| `xFormatPattern("HH:mm")`                 | Changes the format used on the X axis to include only hours and minutes based on a 24-hour clock.                        | 14:45                |
| `xFormatPattern("hh:mm a")`               | Changes the format used on the X axis to include only hours and minutes based on a 12-hour clock with a.m./p.m notation. | 02:45 p.m.           |
| `xFormatPattern("HH:mm:ss")`              | Changes the format used on the X axis to include hours, minutes and seconds.                                             | 14:45:59             |
| `xFormatPattern("yyyy-MM-dd'T'HH:mm:ss")` | Changes the format used on the X axis to show the year, month, day, hour, minute and second.                             | 2017-03-08T 14:45:59 |

> [!NOTE]
> The plotting of time is accurate to approximately 250 nanoseconds. If greater precision is desired, please contact Deephaven Customer Support for guidance.

### Setting Axis Decimal Formatting

A numerical axis can be formatted using [Java DecimalFormat](https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html) strings. See the table below for some of the more common examples.

| Method                                   | Description                                                                                               | Formatted Examples                                                         |
| ---------------------------------------- | --------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| `yFormatPattern("###,###.00")`           | Changes the format of the Y axis and round to two mandatory decimal places.                               | <ul><li>123,456.78</li><li>654.32</li><li>1.99</li></ul>                   |
| `yFormatPattern("\$###,###.00")`         | Changes the decimal format of the Y axis to dollars and cents.                                            | <ul><li>$123,456.78</li><li>$654.32</li><li>$1.99</li></ul>                |
| `yFormatPattern("\$###,###.00 Million")` | Changes the decimal format of the Y axis to dollars and cents, and then add further text to the value.    | <ul><li>$123,456 Million</li><li>$654 Million</li><li>$1 Million</li></ul> |
| `yFormatPattern("###.00%")`              | Changes the Y axis to reflect percentage with two mandatory decimal places.                               | <ul><li>100.11%</li><li>10.22%</li><li>1.5%</li><li>.98%</li></ul>         |
| `yFormatPattern("0.00E00")`              | Changes the Y axis to reflect the value in scientific notation with two decimal places and one exponent.  | <ul><li>1.34E6</li><li>7.80E1</li></ul>                                    |
| `yFormatPattern("##0.00E00")`            | Changes the Y axis to reflect the value in engineering notation with two decimal places and one exponent. | <ul><li>321.34E8</li><li>1.34E6</li><li>.78E2</li></ul>                    |

### Axis Transforms

Axis value ranges can be transformed to specific types with the following methods:

| Method            | Description                                              |
| ----------------- | -------------------------------------------------------- |
| `xLog()`          | Converts the scale of the X axis to a logarithmic scale. |
| `xBusinessTime()` | Converts the scale of the X axis to a business calendar. |

### Plot Orientation

The `plotOrientation` method enables you to transpose the X and Y axes for the chart object.

The default orientation of a chart is vertical – meaning the Y axis of the chart is displayed vertically. The syntax used to transpose the chart axes is shown below:

- `plotOrientation("H")`
- `plotOrientation("HoRiz")`
- `plotOrientation("horizontal")`
- `plotOrientation(PlotOrientation.VERTICAL)`

> [!NOTE]
> The string used as the argument can be any subset of the beginning of the words "horizontal" or "vertical."

## Related documentation

- [Legacy Chart Types](./legacy-plotting.md)
