Fill typesΒΆ

Different ways to plot 2D data.

pcolor, tripcolor, contourf, contour


cols recognized as v0 (19)
data created at /tmp/gp8hyl0n.wt5::/
  axes: ('d1', 'd2')
  shape: (21, 21)
/home/docs/checkouts/ EntireDatasetInMemoryWarning: level
  warnings.warn("level", category=wt_exceptions.EntireDatasetInMemoryWarning)
channel ai0 leveled along axis 0
/home/docs/checkouts/ MatplotlibDeprecationWarning: Passing parameters norm and vmin/vmax simultaneously is deprecated since 3.3 and will become an error two minor releases later. Please pass vmin/vmax directly to the norm when creating it.
  return super().pcolormesh(*args, **kwargs)

<matplotlib.colorbar.ColorbarBase object at 0x7f3d7a5e0fd0>

import matplotlib
import matplotlib.pyplot as plt

import numpy as np

import WrightTools as wt
from WrightTools import datasets

cmap = wt.artists.colormaps["default"]

fig, gs = wt.artists.create_figure(width="double", nrows=2, cols=[1, 1, 1, 1, "cbar"])

# get data
p = datasets.COLORS.v0p2_d1_d2_diagonal
data =, invert_d1=False)
data.level(0, 0, 1)
data.ai0.clip(min=0, replace="value")

def dot_pixel_centers(ax, xi, yi):
    for x in xi:
        ax.scatter([x] * len(xi), yi, edgecolor=None, s=5, color="k")

def decorate(ax):
    ax.set_xlim(-150, 150)
    ax.set_ylim(-150, 150)

# pcolor
ax = plt.subplot(gs[0, 0])
ax.pcolor(data, cmap=cmap)
ax.set_title("pcolor", fontsize=20)
ax = plt.subplot(gs[1, 0])
ax.pcolor(data, cmap=cmap, edgecolors="k")
dot_pixel_centers(ax, data.d1.points, data.d2.points)

# tripcolor
xi = data.d1.points
yi = data.d2.points
zi = data.channels[0][:].T
ax = plt.subplot(gs[0, 1])
points = [xi, yi]
x, y = tuple(np.meshgrid(*points, indexing="ij"))
ax.tripcolor(x.flatten(), y.flatten(), zi.T.flatten(), cmap=cmap, vmin=0, vmax=1)
ax.set_title("tripcolor", fontsize=20)
ax = plt.subplot(gs[1, 1])
ax.tripcolor(x.flatten(), y.flatten(), zi.T.flatten(), edgecolor="k", cmap=cmap, vmin=0, vmax=1)
dot_pixel_centers(ax, xi, yi)

def plot_delaunay_edges(ax, xi, yi, zi):
    x, y = tuple(np.meshgrid(xi, yi, indexing="ij"))
    tri = matplotlib.tri.Triangulation(x.flatten(), y.flatten())
    for i, j in tri.edges:
            [x.flatten()[i], x.flatten()[j]], [y.flatten()[i], y.flatten()[j]], c="k", lw=0.25
        ax.set_xlim(-125, 125)
        ax.set_ylim(-125, 125)

# contourf
ax = plt.subplot(gs[0, 2])
ax.contourf(data, vmin=-1e-3)
ax.set_title("contourf", fontsize=20)
ax = plt.subplot(gs[1, 2])
ax.contourf(data, vmin=-1e-3)
plot_delaunay_edges(ax, xi, yi, zi)
dot_pixel_centers(ax, xi, yi)

# contour
ax = plt.subplot(gs[0, 3])
ax.set_title("contour", fontsize=20)
ax = plt.subplot(gs[1, 3])
plot_delaunay_edges(ax, xi, yi, zi)
dot_pixel_centers(ax, xi, yi)

# label
ticks = [-100, 0, 100]
wt.artists.set_fig_labels(xlabel=data.d1.label, ylabel=data.d2.label, xticks=ticks, yticks=ticks)

# colorbar
cax = plt.subplot(gs[:, -1])
wt.artists.plot_colorbar(cax=cax, label="amplitude")

Total running time of the script: ( 0 minutes 4.013 seconds)

Gallery generated by Sphinx-Gallery