Seeing more detail from a graph of nonlinear equations

50 Views Asked by At

I have a plot of isocontours for nonlinear system of functions and I I'm trying to get more detail in the graph. I know for sure that there are 3 more isocontour (island shapes) inside the iscontour(ring) labelled 1. These would be the local minimas. I do not quite understand how I can zoom further into the graph have them rendering in the diagram.

Quite new to python and Jupyter notebook, would appreciate any insight into how I might do this.

delta = 0.025
x = np.arange(-3, 1.0, delta)
y = np.arange(-3, 2.0, delta)
X, Y = np.meshgrid(x, y)
e1 = X*X + 2*Y*Y + np.sin(2*X)
e2 = X*X + np.cos(X+5*Y) - 1.2
Z = e1**2 + e2**2 

fig, ax = plt.subplots()
CS = ax.contour(X, Y, Z, np.array([1, 5, 10, 50, 100]))
ax.clabel(CS, inline=True, fontsize=10)

Current output

1

There are 1 best solutions below

0
JustLearning On BEST ANSWER

Well, if you know that there are three minima inside the contour of value 1, then you can give smaller values to the levels parameter to see them:

import matplotlib.pyplot as plt                                                                                       
import numpy as np                                                                                                    
                                                                                                                      
                                                                                                                      
delta = 0.025                                                                                                         
x = np.arange(-3, 1.0, delta)                                                                                         
y = np.arange(-3, 2.0, delta)                                                                                         
X, Y = np.meshgrid(x, y)                                                                                              
e1 = X*X + 2*Y*Y + np.sin(2*X)                                                                                        
e2 = X*X + np.cos(X+5*Y) - 1.2                                                                                        
Z = e1**2 + e2**2 # ensure's its positive                                                                             
                                                                                                                      
fig, ax = plt.subplots()                                                                                              
CS = ax.contour(X, Y, Z, np.array([0.1, 1, 5, 10, 50, 100]))                                                          
ax.clabel(CS, inline=True, fontsize=10)                                                                               
ax.set_xlim(-3, 1)                                                                                                    
ax.set_ylim(-2, 1)                                                                                                    
plt.show()                                                                                                            

enter image description here

You can also modify the centering of the axes by using xlim and ylim like I did above: if you make the box smaller, the three minima will be more visible.

enter image description here