Introducing the ‘mpl_stereo’ Library to Make Stereograms and Anaglyphs

When I was a kid growing up in the 90’s, I was fascinated with the “Magic Eye” books. These were picture books filled with images like the one below, which when you did a special technique of “unfocusing” your eyes and staring through the page, transformed into 3D images popping off the page. Learning the trick felt like initiation into a secret club, and to this day the results are more magic than any optical illusion I’ve ever seen. Check out this excellent video for a how-to. It takes some practice to be able to view the stereoscopic effect for the first time, but the effort is well worth it!

Magic Eye – If you know the trick to diverging your eyes, you’ll be able to see a shark popping out at you! (from wikipedia)

I’ve seen a lot of these pictures made for fun (there’s an active community on /r/MagicEye), but none made for practical purposes. This is a huge mistake! Stereographic images can significantly enhance the interpretability of 3D data by leveraging human binocular vision. Instead of looking at a flat projection on a page, stereograms give us “3D glasses” for 2D data with just our eyes.

I’ve been on a data visualization kick recently, working to overhaul Matplotlib’s 3D plotting capabilities with bug fixes and new features. But the end result of those is still a flattened image – I wanted to actually see my plots in 3D space. So, I made a Matplotlib extension called mpl_stereo to do just that!

Check it out on GitHub, or install it right now!

pip install mpl_stereo


Some examples of 2D and 3D plots that pop off the page when you use “divergent” viewing to merge the two plots into one.


If you can’t figure out how to do the stereoscopic eye trick, then you can still see the effect with regular old red-blue 3D glasses. These sorts of plot which you can also make with the library are called “anaglyphs”.

Stereoscopic Images

Or if you already have a pair of stereoscopic images, the library makes it easy to plot as a stereogram or as an anaglyph.

Wiggle Stereograms

Any pair of side-by-side plots can also be turned into a “wiggle stereogram”, or “wigglegram”. Not as precise for examining data, but allows for seeing the 3D effect without training your eyes or using 3D glasses.

  • Post author:
  • Post comments:0 Comments

Leave a Reply