Plotting is a fundamental mode of technical communication (along with writing, speaking, drawings, equations, and code). Good plots can effortlessly convey complex topics, while bad plots can ruin you. Over the years, I’ve developed a handful of little utilities to help me, my team, and my students make prettier plots.

Hatched Lines

Long ago (~January 2006), I needed to produce quality graphics in Java to represent a constrained optimization problem. In this style, a constraint line is drawn with hatches marking the “bad” side of the line. My need to generate quality graphics representing constrained optimization problems keeps coming back. In December 2006, pained by witnessing my students drawing hatches on lines with PhotoShop, I wrote a Matlab version of this tool including a helper for working with constraint data. Most recently (March 2019), my team once again needed to visualize constrained design spaces; this time in Python and Matplotlib. So, in a bit of déjà vu, I wrote the same tool for a third time.

Java

The Java version is implemented as a custom Graphics2D Stroke that draws hatches along a line as the line itself is drawn. Consequently, anything drawn with Java’s Graphics2D can use this custom line style. Others have done much more creative things with custom strokes.

Hatched lines in Java

I also have a couple of 3D versions of this, one in Java3D, the other using a simple software renderer.

Matlab

The Matlab version includes a function hatchedline that is roughly a drop-in replacement for plot and also a helper hatchedcontours to plot contour data with hatched lines. Importantly, Matlab contour data is not oriented, so there is also ocontourc to orient the contour lines consistently.

Hatched lines in Matlab

Python

Similar to the Java approach, the Python version it is implemented as a PathEffect in Matplotlib and should be applicable to any line drawn. I got this feature included in the Matplotlib project in version 3.4.0, so if you use Matplotlib you should already have this.

In Python, ‘hatches’ refer to patterns used to fill polygon plots. To avoid overloading this meaning, I called it TickedStroke in Python.

Hatched lines in Matplotlib

Carpet Plots

Carpet plots are a common means of visualizing multi-dimensional data in certain fields such as aircraft design. These plots depict the response of a system of two independent variables plotted with a cheater axis.

I developed some Matlab tools that make generating carpet plots easier. Routines for labeling the axes, placing text labels, and converting contour lines to the carpet plot axes are also included.

Carpet plot in Matlab

Contour Labels

Positioning contour labels in Matlab is a hassle. Automatic placement is ugly and inconsistent while interactive placement is interactive and either painstaking or inconsistent.

This tool, clabel_along, allows the user to specify a curve along which to place contour labels. This gives the user a great deal of control for contour placement, but it also provides a system that is easily automated with repeatable results.

clabel_along example in Matlab

Text Labels

Using MATLAB’s text to label points along a parametric curve often results in the label blocking the curve. This can be avoided for simple curves by using the text alignment properties or by offsetting the points. However, these techniques do not work for curves that change direction.

This tool, ptlabel_along, interpolates the provided curve to place points at just the desired parameter values. It also computes the local slope of the line and uses that to offset the text perpendicular to the line. This makes labeling parameter values along curves easy and beautiful.

ptlabel_along example in Matlab