With what command i can change the width of contours created with SURFC from the beginning?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Hi friends
I created a 3D figure using SURFC. Now I want to increase the width of contours appeared in figure to 2, but I can not select contours to change their width. How can I plot the figure with wider contours from the beginning (what property or command)?
thank you
Accepted Answer
Mike Garrity
on 19 Jan 2016
The property is LineWidth, but things are a little tricky with surfc. The surfc command turns around and calls surf and contour. It is going to pass all of the property/value pairs you give it to the surf command, not the contour command. That means that if we do this:
surfc(peaks,'LineWidth',4)
We'll get wide lines on our surface, rather than on our contour.
The easiest way to set properties on the contour object is to get the return value from surfc.
h = surfc(peaks)
This should say something like this:
h =
2x1 graphics array:
Surface
Contour
That's saying that h is an array of two graphics objects. The first is the surface and the second is the contour. That means that we can do things like this:
h(2).LineWidth = 4
6 Comments
Moein
on 19 Jan 2016
thanks Mike
but can you apply your method on following code?
T=linspace(-pi/8,pi/8,30);
R=linspace(0,1,30);
[t, r]=meshgrid(T, R);
z=(0.2079921258e1 .* (cos((4 .* t)) .^ 2 .* ((4 .* r .^ 3 - 2 .* r) .^ 2) ./ 0.144e3 + sin((4 .* t)) .^ 2 .* ((r .^ 4 - r .^ 2) .^ 2) ./ (r .^ 2) ./ 0.9e1) ./ (-0.1361305280e0 .* cos((4 .* t)) .* (r .^ 4 - r .^ 2) + 0.1e1) + 0.1e1) ./ (-0.1361305280e0 .* cos((4 .* t)) .* (r .^ 4 - r .^ 2) + 0.1e1);
[x,y,z]=pol2cart(t,r,z);
surfc(x,y,z,'FaceColor','interp','FaceLighting','phong');
Sure. In that last line, you're setting the values of the FaceColor and FaceLighting properties on the surf object. But you also want to set the LineWidth property on the contour object. To do that, you'll need to get the return value from surfc.
h = surfc(x,y,z,'FaceColor','interp','FaceLighting','phong');
h(2).LineWidth = 3;

i don't know how i can get the return value from surfc to contours. i raplaced the last line in my code with two lines that you wrote and then wrote the following code. but it errors: "??? Structure assignment to non-structure object." is it because of my matlab's version? i'm using R2010b.
the code:
T=linspace(-pi/8,pi/8,30);
R=linspace(0,1,30);
[t, r]=meshgrid(T, R);
z=(0.2079921258e1 .* (cos((4 .* t)) .^ 2 .* ((4 .* r .^ 3 - 2 .* r) .^ 2) ./ 0.144e3 + sin((4 .* t)) .^ 2 .* ((r .^ 4 - r .^ 2) .^ 2) ./ (r .^ 2) ./ 0.9e1) ./ (-0.1361305280e0 .* cos((4 .* t)) .* (r .^ 4 - r .^ 2) + 0.1e1) + 0.1e1) ./ (-0.1361305280e0 .* cos((4 .* t)) .* (r .^ 4 - r .^ 2) + 0.1e1);
[x,y,z]=pol2cart(t,r,z);
h = surfc(x,y,z,'FaceColor','interp','FaceLighting','phong');
h(2).LineWidth = 3;
Sorry, the 'dot notation' was introduced in R2014b. In R2010b, you'll need to use the set command.
set(h(2),'LineWidth',3)
Moein
on 19 Jan 2016
so funny! new problem!
just one contour (the smallest one) shaped with wider curve.
other ones shaped as before. look at the attached photo.

at last i found the answer.following code:
T=linspace(-pi/8,pi/8,30);
R=linspace(0,1,30);
[t, r]=meshgrid(T, R);
z=(0.2079921258e1 .* (cos((4 .* t)) .^ 2 .* ((4 .* r .^ 3 - 2 .* r) .^ 2) ./ 0.144e3 + sin((4 .* t)) .^ 2 .* ((r .^ 4 - r .^ 2) .^ 2) ./ (r .^ 2) ./ 0.9e1) ./ (-0.1361305280e0 .* cos((4 .* t)) .* (r .^ 4 - r .^ 2) + 0.1e1) + 0.1e1) ./ (-0.1361305280e0 .* cos((4 .* t)) .* (r .^ 4 - r .^ 2) + 0.1e1);
[x,y,z]=pol2cart(t,r,z);
h=surfc(x,y,z,'FaceColor','interp','FaceLighting','phong');
for i=2:16
set(h(i),'LineWidth',2)
end
thank you very much Mike for your help.
More Answers (0)
Categories
Find more on Contour Plots in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)