Polar fill sector

34 次查看(过去 30 天)
Jay
Jay 2011-6-19
编辑: Toshia M 2024-4-30
Hey. I wanted to fill a sector of a polar graph with a specified colour. For example, say I wanted to create a polar plot and fill the area 1<r<2, pi/8 < theta < 2pi/8 with the colour [0 1 1], how would I code this. Is this possible? I need to fill many sectors so there will be a list of them.

回答(3 个)

Toshia M
Toshia M 2024-4-30
编辑:Toshia M 2024-4-30
Starting in R2024a, you can use the polarregion function to create a polar rectangle with specific bounding angles and radii. For example:
thetas = [pi/8 2*pi/8];
radii = [1 2];
figure
polarregion(thetas,radii)
By default, the rectangle is a semitransparent gray, but you can optionally specify the color and add a border around the rectangle. For example, you can create a blue rectabgle with a black border:
figure
polarregion(thetas,radii,FaceColor="blue",EdgeColor="black")

Walter Roberson
Walter Roberson 2011-6-19
Unfortunately the way to do this would be to construct a point list of boundary points, pol2cart() them, and fill() the cartesian polygon.
The point list would have to be relatively dense along theta in order to get nice curves, but the edges of the wedges could just have the two endpoints as those translate in to a straight line in cartesian space.
  2 个评论
Naor Movshovitz
Naor Movshovitz 2016-11-15
@Walter any chance this approach can be improved upon using the new (R2016a) polar axes object?
Walter Roberson
Walter Roberson 2016-11-15
How odd!
If you record the output from polarplot() that was allowed to create its own polar axes, then the output is type Line, class class matlab.graphics.primitive.Line . And it will have a bunch of properties including ThetaData and RData. If, inside that polar axes, you use line(), then you get one of those type of lines with that class and those properties.
If you record the output from line() in a normal axes, then the output is type Line, class matlab.graphics.primitive.Line -- exactly the same type and class. But it has XData and YData properties, not RData and ThetaData properties.
Now, if you set the Parent of a normal line to be a polar axes then it suddenly changes flavor into one suited for polar !
Ah... ah... looks like the difference is in how they display! Both objects have both property pairs and they are tied together, but if the parent is a polar axes then the polar variants are displayed and otherwise the XY variants are displayed

请先登录,再进行评论。


Gurudatha Pai
Gurudatha Pai 2011-6-19
I was just wondering if the pie chart could be intelligently used to obtain the same result. @Walter: You would probably know better about modifying pie charts!
  1 个评论
Walter Roberson
Walter Roberson 2011-6-19
I think that approach would be longer.
The documentation for pie() indicates that patches are created. Those patches always come to a point, and so would have to be modified to instead follow the inner radius. Then you would have to add the radial and angular axes lines and notations. Easier to pol2cart() and fill() vectors.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Polar Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by