10

I want a radial(polar) plot using gnuplot (i.e in circular co-ordinate system(r,theta).

Here I have used the values:

Theta Max-strain
0     3400
60    5300
120   4700
180   3800
240   4100
300   3100
360   3400

How to get such a plot using gnu-plot?

Thor
  • 45,082
  • 11
  • 119
  • 130
Dolly
  • 277
  • 2
  • 7
  • 16
  • 3
    You might want to get rid of the 360° in your plot since it is redundant with the 0°... – Woltan Jul 22 '11 at 09:26

2 Answers2

30

I tried to recreate the plot of your question and this is what I came up with:

unset border
set polar
set angles degrees #set gnuplot on degrees instead of radians

set style line 10 lt 1 lc 0 lw 0.3 #redefine a new line style for the grid

set grid polar 60 #set the grid to be displayed every 60 degrees
set grid ls 10

set xrange [-6000:6000] #make gnuplot to go until 6000
set yrange [-6000:6000]

set xtics axis #disply the xtics on the axis instead of on the border
set ytics axis

set xtics scale 0 #"remove" the tics so that only the y tics are displayed
set xtics ("" 1000, "" 2000, "" 3000, "" 4000, "" 5000, "" 6000) #set the xtics only go from 0 to 6000 with increment of1000 but do not display anything. This has to be done otherwise the grid will not be displayed correctly.
set ytics 0, 1000, 6000 #make the ytics go from the center (0) to 6000 with incrment of 1000

set size square 

set key lmargin

set_label(x, text) = sprintf("set label '%s' at (6500*cos(%f)), (6500*sin(%f))     center", text, x, x) #this places a label on the outside

#here all labels are created
eval set_label(0, "0")
eval set_label(60, "60")
eval set_label(120, "120")
eval set_label(180, "180")
eval set_label(240, "240")
eval set_label(300, "300")


set style line 11 lt 1 lw 2 pt 2 ps 2 #set the line style for the plot

#and finally the plot
plot "-" u 1:2 t "Max strain" w lp ls 11
0 3400
60 5300
120 4700
180 3800
240 4100
300 3100
360 3400
e

Plot of the script above

As you can see, the major difference is that the angle 0 is not on top but on the right (which is mathematically correct). You can change this however by modifying the using deceleration in the plot and the set_label function.

As you can see in the script not everything is really crisp and shiny. If someone finds improvements please let me know!

One last bit of "advice": It is not always reasonable to try to reproduce a plot from some tool with gnuplot. Often the strength of gnuplot is to plot data in the most simple way to be easily reproducible. Maybe you can kick some lines out of that script above and still be happy with it.

Woltan
  • 13,723
  • 15
  • 78
  • 104
  • Thank you so much. It was very helpful. I tried using set_label exactly as you have mentioned above, but got an error. With out labels its working fine. Also what if there are negative values say -3400,-5300 etc... then in the plot above instead of 6000 to 0 in the y axis, it should go 0 to -6000 inwards. Similar to the plot you get in MS Excel. How to get such a plot? – Dolly Jul 25 '11 at 08:58
  • @Dolly The `set_label` macro is working on my machine. What is the error message? As for negative values: In a polar plot you cannot have negative values, since the value is more or less a radius and a radius cannot be negative. If you have negative values, maybe you should not use a polar plot or maybe map it with `exp` and `log`?! – Woltan Jul 25 '11 at 09:05
  • 1
    When I use set_label plot is not getting created. When I don't use set_label then plot gets created.Is the option not available in older gnu-plot version? Where can I download new version? – Dolly Jul 31 '11 at 16:26
  • 1
    @Dolly I don't know what version of gnuplot you must have in order for macros to work. But it is always a good idea to have the latest version. You can get them from [here](http://sourceforge.net/projects/gnuplot/files/gnuplot/). – Woltan Jul 31 '11 at 18:24
  • @ Woltan: Now everything works fine after I downloaded and installed latest version of gnu-plot. One last question, finally while plotting how to read (r,theta) values from another text file instead of directly giving it here in .plt file. – Dolly Aug 01 '11 at 10:26
  • 1
    @Dolly Substitute `"-"` with the filename where the values are in. So something like: `plot "Data.dat" u 1:2 ...`. – Woltan Aug 01 '11 at 10:49
  • @Woltan I get with the macro this: "rem_angle_polar.gnu", line 13: ')' expected" for the line after macro. I have gnuplot 5.0. Do you understand the error? – Léo Léopold Hertz 준영 Mar 31 '15 at 07:50
6

Here is a manual http://t16web.lanl.gov/Kawano/gnuplot/polar-e.html

 set polar
 set angles degrees

and to get circles:

 set grid polar

Here is a demo: http://gnuplot.sourceforge.net/demo/polar.html

osgx
  • 90,338
  • 53
  • 357
  • 513
  • 2
    Thanks. I have already tried using set grid polar. But I could not show the angles in it and I had to specify x and y and the obtained plot did not match with what I wanted. I have re-framed my question now. Hope I am clear this time. – Dolly Jul 21 '11 at 07:13
  • try to do `plot data ... with lines`. – osgx Jul 21 '11 at 08:46
  • `set grid polar 30 ` will add grid with line each 30 degrees. – osgx Jul 21 '11 at 08:50