4

Following code is borrowed from here:

import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt


delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2

fig, ax = plt.subplots()
CS = ax.contour(X, Y, Z)
ax.clabel(CS, inline=True, fontsize=10)
ax.set_title('Simplest default with labels')

The above code produces the contour plot with 7 contour lines. How to draw a single contour line say with the value 0.5?

The output of the above code is:

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Aim
  • 389
  • 6
  • 20

1 Answers1

3

Just add contour value: CS = ax.contour(X, Y, Z, [0.5])

import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt


delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2

fig, ax = plt.subplots()
CS = ax.contour(X, Y, Z, [0.5])
ax.clabel(CS, inline=True, fontsize=10)
ax.set_title('Simplest default with labels')

plt.show()

enter image description here