Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw an annulus segment in GNUPlot

I would like to shade a specific region in a polar plot using GNUPlot. This region is bounded by limits in R (r1, r2) and Theta (t1, t2), so the final shape is an annulus segment defined by only 4 points in polar space.

In a Cartesian plot, it is quite easy to draw a rectangle, either by (set object rect) or filledcurve of a closed shape with 4 vertices. However, a filledcurve shape specified by 4 points in a polar plot still results in a quadrilateral (lines with constant R should be circular arcs, not straight lines).

Is there a simple or straightforward way to plot this shape in polar coordinates? I've tried using two arcs and then filling the space between them, but this has not been working correctly so far and I'm not sure if there's a better way to go about this.

like image 362
user4815162342 Avatar asked Aug 18 '14 21:08

user4815162342


1 Answers

Unfortunately, that is not too easy. You can set a circle object for which you specify the begin and end angles. To cut out the center part you must draw a second white circle above:

set xrange [-1:1]
set yrange [-1:1]
set size ratio -1

r1 = 0.5
r2 = 1
theta1 = -30
theta2 = 60

set angles degrees
set style fill solid noborder
set object circle at first 0,0 front size r2 arc [theta1:theta2] fillcolor lt 1
set object circle at first 0,0 front size r1 fillcolor rgb 'white'

plot -10 notitle

Here it is essential, that x and y axis have the same unit (set size ratio -1), because a circle object is defined in units of the first x-axis and does not respect the y-axis at all. If you don't have anything else to plot, you must use a plot command which plots something outside of the defined ranges. Without a plot the objects aren't drawn.

The result with 4.6.5 is:

enter image description here

With the upcoming 5.0 version you can use pseudo-data (with the special file name +) together with the filledcurves plotting style:

r1 = 0.5
r2 = 1.0
theta1 = 20
theta2 = 135
set polar
set angles degrees
set size ratio -1
unset raxis
unset rtics
set trange [theta1:theta2]
set style fill solid noborder
plot '+' using 1:(r1):(r2) with filledcurves notitle

enter image description here

like image 72
Christoph Avatar answered Nov 04 '22 04:11

Christoph