vvmtools.plot.DataPlotter.draw_zt#
- DataPlotter.draw_zt(data, levels, extend, pblh_dicts={}, cmap_name='bwr', title_left='', title_right='', xlim=None, ylim=None, figname='')[source]#
This function creates a z-t plot for a specified variable over time and height dimensions. and draw a series pbl height 1-D datasets.
- Parameters:
data (np.ndarray) – 2D array (nz,nt) of data values to plot, with dimensions corresponding to time (‘t’) and height (‘z’) axes.
levels (list or np.ndarray) – Sequence of boundaries to use for color normalization.
extend (str) – Controls the color scaling at the boundaries. Accepts ‘both’, ‘neither’, ‘min’, or ‘max’ to adjust color mapping.
pblh_dicts (dict, optional) – Dictionary of planetary boundary layer height data with labels as keys and height values as arrays (nt). Optional.
cmap_name (str, optional) – Name of the colormap for the plot. Defaults to ‘bwr’.
title_left (str, optional) – Title text displayed at the left of the plot.
title_right (str, optional) – Title text displayed at the right of the plot.
xlim (tuple, optional) – Limits for the x-axis (time), specified as a tuple (start, end). Defaults to None, which uses the full domain range.
ylim (tuple, optional) – Limits for the y-axis (height), specified as a tuple (start, end). Defaults to None, which uses the full domain range.
figname (str, optional) – File name for saving the generated plot. If left empty, the plot will not be saved.
- Returns:
The figure, main axis, and colorbar axis of the created plot.
- Return type:
tuple (matplotlib.figure.Figure, matplotlib.axes._axes.Axes, matplotlib.colorbar.Colorbar)
Examples
Initialize the DataPlotter Classes
import numpy as np from vvmtools.plot import DataPlotter import matplotlib.pyplot as plt # 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)
Create the 2d data.
np.random.seed(0) data_zt2d = np.random.normal(0, 0.1, size=(nz,nt)) line1_1d = np.sin( np.linspace(0, 2*np.pi, nt) ) +1 line2_1d = np.cos( np.linspace(0, 2*np.pi, nt) ) +1
draw z-t diagram.
fig, ax, cax = dplot.draw_zt(data = data_zt2d, levels = np.arange(-1,1.001,0.1), extend = 'both', pblh_dicts={'line1': line1_1d, 'line2': line2_1d, }, title_left = 'draw_zt pblh example', title_right = f'right_land_type', figname = 'test_pbl.png', ) plt.show()
draw z-t diagram with optional configuration.
fig, ax, cax = dplot.draw_zt(data = data_zt2d, levels = np.arange(-1,1.001,0.1), extend = 'both', pblh_dicts={'line1': line1_1d, 'line2': line2_1d, }, cmap_name = 'Spectral', xlim = (np.datetime64('2024-01-01 09:00:00'), np.datetime64('2024-01-01 17:00:00') ), ylim = (0, 1), title_left = 'draw_zt (optional)', title_right = f'right_land_type', figname = '', ) plt.show()