Filter löschen
Filter löschen

Polar fill sector

31 Ansichten (letzte 30 Tage)
Jay
Jay am 19 Jun. 2011
Bearbeitet: Toshia M am 30 Apr. 2024
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.

Antworten (3)

Toshia M
Toshia M am 30 Apr. 2024
Bearbeitet: Toshia M am 30 Apr. 2024
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 am 19 Jun. 2011
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 Kommentare
Naor Movshovitz
Naor Movshovitz am 15 Nov. 2016
@Walter any chance this approach can be improved upon using the new (R2016a) polar axes object?
Walter Roberson
Walter Roberson am 15 Nov. 2016
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

Melden Sie sich an, um zu kommentieren.


Gurudatha Pai
Gurudatha Pai am 19 Jun. 2011
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 Kommentar
Walter Roberson
Walter Roberson am 19 Jun. 2011
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Polar Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by