Re:Show HN: UltraPlot. A Succinct Wrapper for Matplotlib
by cvanelteren on Sunday September 14, 2025 @09:00AM
(#45239488)
You are right. I was doubting whether to make a more complicated example -- but formatting is poor in text boxes. Let me give you a more complex one.
Let's say we want a 3-column plot: colormesh, polar, and geo plot.
UltraPlot:
import ultraplot as uplt, numpy as np
fig, ax = uplt.subplots(
ncols=3, share=0, proj="cart polar merc".split(), journal="nat2"
)
ax[0].pcolormesh(
np.random.rand(10, 10), cmap="viko", colorbar="r",
colorbar_kw=dict(title="some interesting colors")
)
angles, radii = np.random.rand(100) * 360, np.random.rand(100)
ax[1].scatter(angles, radii, c=radii, cmap="spectral_r")
x, y = np.meshgrid(np.linspace(-30, 30, 100), np.linspace(-60, 60, 100))
z = np.exp(-(x*2 + y*2) / 100)
ax[2].pcolormesh(x, y, z, cmap="Fire")
ax[2].format(landcolor="green", land=True, grid=True, lonlabels=True, latlabels=True)
ax.format(abc="[A]")
fig.show()
Matplotlib equivalent: import matplotlib.pyplot as plt, numpy as np, cartopy.crs as ccrs
fig = plt.figure(figsize=(15, 5))
ax0 = fig.add_subplot(1, 3, 1)
pcm = ax0.pcolormesh(np.random.rand(10, 10), cmap="viridis")
cbar = plt.colorbar(pcm, ax=ax0)
cbar.set_label("some interesting colors")
cbar.ax.yaxis.label.set_color("r")
ax1 = fig.add_subplot(1, 3, 2, projection="polar")
angles = np.random.rand(100) * 2 * np.pi
radii = np.random.rand(100)
sc = ax1.scatter(angles, radii, c=radii, cmap="Spectral_r")
ax2 = fig.add_subplot(1, 3, 3, projection=ccrs.Mercator())
x, y = np.meshgrid(np.linspace(-30, 30, 100), np.linspace(-60, 60, 100))
z = np.exp(-(x*2 + y*2) / 100)
pcm2 = ax2.pcolormesh(x, y, z, cmap="magma", transform=ccrs.PlateCarree())
ax2.coastlines()
ax2.gridlines(draw_labels=True)
ax2.set_extent([-30, 30, -60, 60], crs=ccrs.PlateCarree())
import cartopy.feature as cfeature
ax2.add_feature(cfeature.LAND, facecolor="green")
for i, ax in enumerate([ax0, ax1, ax2]):
ax.set_title(f"[{chr(65+i)}]")
plt.tight_layout()
plt.show()
The aim isn't to replace matplotlib but make publication-ready plots with fewer keystrokes and better defaults. We also bundle plot types not available in matplotlib like graph plotting, lollipop charts, heatmaps etc.
Re:Show HN: UltraPlot. A Succinct Wrapper for Matplotlib
by zahlman on Sunday September 14, 2025 @09:05AM
(#45239519)
> You are right. I was doubting to make a more complicated example -- but formatting is poor on txt boxes.
I see now that you have an example in the README. I think it would be better still in the README, but as plain text rather than rendered into an SVG.
This would be more convincing if you showed the equivalent Matplotlib code and demonstrated that any improvements are not just a result of default settings being a closer match for what the example tries to do. The code shown here looks more or less like what I'd expect a Matplotlib hello-world to look like.