Clear Filters
Clear Filters

controlling the spread of contour lines

7 views (last 30 days)
I have the following code which plots a filled contour. I want more closed contours towards the center of the figure because they are more important to me. How can I control the spacing of the contour lines?
% Function to plot contours
x1=-5:0.1:5;
x2=-5:0.1:5;
[a ,b]=meshgrid(x1,x2);
f=(2.*(a).^2)-(1.05.*(a).^4)+((a.^6)./6)+(a.*b)+(b.^2);
[c,h]=contourf(a,b,f,20);
clabel(c,h);

Answers (1)

Star Strider
Star Strider on 9 Nov 2018
You can define the contour levels with a vector.
Example
% Function to plot contours
x1=-5:0.1:5;
x2=-5:0.1:5;
[a ,b]=meshgrid(x1,x2);
f=(2.*(a).^2)-(1.05.*(a).^4)+((a.^6)./6)+(a.*b)+(b.^2);
lvls = exp(-10:0.1:7.5); % Define Contour Levels
[c,h]=contourf(a,b,f,lvls);
clabel(c,h);
The ‘lvls’ vector creates an exponentially-increasing set of contours. You can use any vector you want.

Categories

Find more on Contour Plots in Help Center and File Exchange

Tags

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!