-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontour_plot.py
43 lines (30 loc) · 969 Bytes
/
contour_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 2 00:23:06 2019
Contour plot
- modify the number of countour lines with the variable 'tightness'
@author: alberto
"""
import numpy as np
import matplotlib.pyplot as plt
def f(x, y):
return (1 - x / 2 + x ** 5 + y ** 3) * np.exp(-x ** 2 - y ** 2)
n = 256
x = np.linspace(-3, 3, n)
y = np.linspace(-3, 3, n)
# Defines number of contour lines
tightness = 10
# Create coordinate matrices from coordinate vectors
X, Y = np.meshgrid(x, y)
# contourf fills between contour lines using cmap
plt.contourf(X, Y, f(X, Y), tightness, alpha=0.75, cmap='hot')
# contour draws contour lines and saves as CoutourSet object
C = plt.contour(X, Y, f(X, Y), tightness, colors='black', linewidth=0.5)
# pass ContourSeet object to command clabel to label the contour lines
plt.clabel(C)
# Hide axis
plt.axis('off')
# Save figure using 72 dots per inch
plt.savefig('contour_plot.png', dpi=72)
plt.show()