O'Reilly logo

matplotlib Plotting Cookbook by Alexandre Devert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Visualizing contour lines

So far, we have visualized data by coloring each data point and have thrown in some interpolation on top. matplotlib is able to provide more sophisticated representations for 2D data. Contour lines link all points with the same value, helping you to capture features that might not be easily seen otherwise. In this recipe, we will see how to display such contour lines.

How to do it...

The function pyplot.contour() allows you to generate contour annotations. To demonstrate this, let's reuse our code from the previous recipes in order to study a zoomed-in part of the Mandelbrot set:

import numpy as np from matplotlib import pyplot as plt import matplotlib.cm as cm def iter_count(C, max_iter): X = C for n in range(max_iter): ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required