2D CSDM objects with imshow()\contour()\contourf()ΒΆ

2D{1} datasetsΒΆ

# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np

import csdmpy as cp

# Create a test 2D{1} dataset. ================================================
# Step-1: Create a new csdm object
csdm = cp.new()

# Step-2: Create dimension objects and add it to the CSDM object.
x1 = cp.as_dimension(np.arange(10) * 0.1 + 15, unit="s", label="t1")
csdm.add_dimension(x1)
x2 = cp.as_dimension(np.arange(10) * 12.5, unit="s", label="t2")
csdm.add_dimension(x2)

# Step-3: Create dependent variable objects and add it to the CSDM object.
y = cp.as_dependent_variable(np.diag(np.ones(10)), name="body-diagonal")
csdm.add_dependent_variable(y)


# Plot imshow =================================================================
plt.figure(figsize=(5, 3.5))
# create the axes with `projection="csdm"`
ax = plt.subplot(projection="csdm")
# use matplotlib imshow function with csdm object.
ax.imshow(csdm, origin="upper", aspect="auto")
plt.tight_layout()
plt.show()

(Source code, png, hires.png, pdf)

../_images/twoD_plot_00_00.png
# Plot contour ================================================================
plt.figure(figsize=(5, 3.5))
# create the axes with `projection="csdm"`
ax = plt.subplot(projection="csdm")
# use matplotlib contour function with csdm object.
ax.contour(csdm)
plt.tight_layout()
plt.show()

(png, hires.png, pdf)

../_images/twoD_plot_01_00.png

2D{1, 1, ..} datasetsΒΆ

Plotting on the same AxesΒΆ

When multiple single-component dependent variables are present within the CSDM object, the data from all dependent-variables is plotted on the same axes. The name of each dependent variable is displayed along the color bar.

# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np

import csdmpy as cp

# Create a test 2D{1} dataset. ================================================
# Step-1: Create a new csdm object
csdm = cp.new()

# Step-2: Create dimension objects and add it to the CSDM object.
x1 = cp.as_dimension(np.arange(10) * 0.1 + 15, unit="s", label="t1")
csdm.add_dimension(x1)
x2 = cp.as_dimension(np.arange(10) * 12.5, unit="s", label="t2")
csdm.add_dimension(x2)

# Step-3: Create dependent variable objects and add it to the CSDM object.
y = cp.as_dependent_variable(np.diag(np.ones(10)), name="body-diagonal")
csdm.add_dependent_variable(y)
y = cp.as_dependent_variable(np.diag(np.ones(5), 5), name="off-body-diagonal")
csdm.add_dependent_variable(y)


# Plot imshow =================================================================
plt.figure(figsize=(5, 3.5))
# create the axes with `projection="csdm"`
ax = plt.subplot(projection="csdm")
# use matplotlib imshow function with csdm object.
ax.imshow(csdm, origin="upper", aspect="auto", cmaps=["Blues", "Reds"], alpha=0.5)
plt.tight_layout()
plt.show()

(Source code, png, hires.png, pdf)

../_images/twoD111_plot_00_00.png
# Plot contourf ===============================================================
plt.figure(figsize=(5, 3.5))
# create the axes with `projection="csdm"`
ax = plt.subplot(projection="csdm")
# use matplotlib contourf function with csdm object.
ax.contourf(csdm, cmaps=["Blues", "Reds"], alpha=0.5)
plt.tight_layout()
plt.show()

(png, hires.png, pdf)

../_images/twoD111_plot_01_00.png

Plotting on separate AxesΒΆ

To plot the data from individual dependent variables onto separate axes, use the split() method to first split the CSDM object with n dependent variables into n CSDM objects with single dependent variables, and then plot them separately.