Question

I am trying to draw something similar: enter image description here

The main idea is to draw ellipses with different color in some specific range, for example from [-6, 6].

I have understood that plt.contour function can be used. But I do not understand how to generate lines.

Was it helpful?

Solution

I personally wouldn't do this with contour as you then need to add information about the elevation which I don't think you want?

matplotlib has Ellipse which is a subclass of Artist. The following example adds a single ellipse to a plot.

import matplotlib as mpl
ellipse = mpl.patches.Ellipse(xy=(0, 0), width=2.0, height=1.0)
fig, ax = plt.subplots()
fig.gca().add_artist(ellipse)

ax.set_aspect('equal')
ax.set_xlim(-2, 2)
ax.set_ylim(-2, 2)

enter image description here

You then need to research how to get the effect you are looking for, I would have a read of the docs in general making things transparent is done through alpha.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top