plot module

plot module#

class vvmtools.plot.DataPlotter(exp, figpath, domain, units, ticks=None, time_fmt='%H')[source]#

Bases: object

The DataPlotter class provides methods for creating and saving visualizations of scientific data across spatial and temporal dimensions.

This class enables users to configure plotting attributes, including axis data, units, and custom tick locations, while offering utilities for automatically setting up figure paths and managing plot layouts. Custom color maps, label formatting, and title settings can be applied to generated plots for clear and detailed data presentation.

Parameters:
  • exp (str) – Experiment name or identifier for labeling the plots.

  • figpath (str) – Directory path where generated figures will be saved. If the directory does not exist, it is created automatically.

  • domain (dict) – Dictionary containing data arrays for plotting dimensions, with keys ‘x’, ‘y’, ‘z’, and ‘t’. np.array values are expected for spatial axes and np.datetime64 for time (‘t’).

  • units (dict) – Dictionary defining the units of each axis, with keys ‘x’, ‘y’, ‘z’, and ‘t’. The values are strings specifying the units displayed on axis labels.

  • ticks (dict, optional) – Custom tick locations for each axis, with keys ‘x’, ‘y’, ‘z’, and ‘t’. If not provided, default tick settings are used.

  • time_fmt (str, optional) – Format for displaying labels on the time axis. Default is ‘%H’, for displaying hours in 24-hour format.

Examples

import numpy as np
from vvmtools.plot import DataPlotter

# prepare expname and data coordinate
expname  = 'pbl_control'
nx = 128; x = np.arange(nx)*0.2
ny = 128; y = np.arange(ny)*0.2
nz = 50;  z = np.arange(nz)*0.04
nt = 721; t = np.arange(nt)*np.timedelta64(2,'m')+np.datetime64('2024-01-01 05:00:00')

# create dataPlotter class
figpath           = './fig/'
data_domain       = {'x':x, 'y':y, 'z':z, 't':t}
data_domain_units = {'x':'km', 'y':'km', 'z':'km', 't':'LocalTime'}
dplot = DataPlotter(expname, figpath, data_domain, data_domain_units)

Attributes#

  • EXP: Experiment name or identifier, used to label plots.

  • FIGPATH: Path for saving generated figures.

  • DOMAIN: Dictionary with data arrays for plotting dimensions (‘x’, ‘y’, ‘z’, and ‘t’).

  • DOMAIN_UNITS: Dictionary defining units for each axis.

  • CUSTOM_TIME_FMT: Custom time format for labels on the time axis.

  • DOMAIN_TICKS: Dictionary with default or user-specified tick locations for each axis.

Methods#

vvmtools.plot.DataPlotter.draw_xt(data, ...)

This function creates a x-t plot for a 2D data over spatial (x or y) and temporal (t) dimensions.

vvmtools.plot.DataPlotter.draw_zt(data, ...)

This function creates a z-t plot for a specified variable over time and height dimensions.