1

Sometimes data to be plotted on a polar plot take large values in a specific direction. Is it possible to shape a polar plot created with pgfplots and the polaraxis environment (for example via clipping) so that it looks like the following picture?

enter image description here

2 Answers 2

3

pgfplots supports no boxed polar plots of this sort.

You can merely reduce the plotted range using xmin and xmax.

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.13}

\begin{document}

\begin{tikzpicture}
      \begin{polaraxis}[
        xmin=0,
        xmax=180,
        ytick distance=0.2,
        yticklabel style={anchor=near yticklabel opposite},
        minor x tick num=2,
        grid=both,
      ]
      \addplot[blue] table {
        0 1
        10 0.7
        20 0.5
        60 0.2
        80 0.25
        90 0.26
        100 0.25
        120 0.2
        160 0.5
        180 1
        };
      \end{polaraxis}
\end{tikzpicture}

\end{document}

enter image description here

1
  • 1
    Hi Christian! That's what I ended up doing at the end. Thanks! (A boxed polar plot would be a nice new feature though.)
    – Antonio
    Sep 22, 2016 at 7:42
0

Here's a way to do it manually with Tikz. By intention I left it in its rudimentary form, i.e. without any paramaters to adjust to:

  • to show, what actions have to be done
  • to indicate, what kind of decision making may be needed

To write your own plot handlers please turn to chapters 65 and 112.3 in the current pgfmanual.

COMMENTS:

(1), (2) and (3) deal with placing nodes for labels, before clipping is applied.

Kindly note that at the top the space got very crowded for the angles, so an intelligent plot handler will account for this.

Instead of using trigonometrics to calculate node coordinates you can also switch to intersections, provided by Tikz.

(4) clips everything that follows. Can certainly be replaced by a rectangle command ;-)

(5) draws the circles, while (6) draws the radii.

(7) plots 2 data sets given in Tikz' polar coordinates. Please note that the angles used in the screenshot shown by the OP doesn't make too much sense.

(8) overdraws the frame again to have the correct top colors. This could certainly be done with more elegance, e.g. by moving the frame's code into a top layer to be drawn as the last one.

In general using layers may be an approach worth considering. // Though one is tempted to move more actions into \foreach loops, here I split the action, often for a more uniform color density (i.e. avoiding overdrawing) and also to account for the tan(90) situation ...

result

\documentclass[10pt,border=3mm,tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
 \begin{tikzpicture}[
    grd/.style={gray!60},
    lbl/.style={anchor=north},
 ]
    % ~~~ (1) x-axis labels ~~~~~~~~~
    \foreach \L in {1,2,3,4}    {
        \node[lbl] at ( \L,0) {\L};
        \node[lbl] at (-\L,0) {\L};
    }
    \node[lbl] at (0,0) {0};
        
    % ~~~ (2) angle labels vertical ~~~~~
    \foreach \w in {10,20}
        \node[anchor=west] at ($tan(\w)*(0,4) + (4,0)$) {$\w^\circ$};
    \foreach \w in {170,160}
        \node[anchor=east] at ($tan(\w)*(0,-4) + (-4,0)$) {$\w^\circ$};
        
    % ~~~ (3) angle labels horizontal ~~~~~
    \foreach \w in {30,40,50,70,150,140,130,110}
        \node[anchor=south] at 
            ($2/tan(\w)*(1,0) + (0,2)$) {$\w^\circ$};
    \node[anchor=south] at  (0,2) {$90^\circ$};
    
    % ~~~ (4) clip ~~~~~~~~~~~~~~~~~~
    \draw[clip] (-4,0) -- (4,0) -- (4,2) -- (-4,2) -- cycle; 

    % ~~~ (5) circular lines ~~~~~~~~~
    \foreach \r in {1,2,3,4} 
        \draw[grd] (\r,0) 
            arc[start angle=0, end angle=180,radius=\r] -- cycle;   
    % ~~~ (6) radii ~~~~~~~~~~~~~~~~~~~~~~
    \foreach \w in {0,10,...,180}
        \draw[grd] (0,0) -- (\w:5) node{\w};
    
    % ~~~ (7) data ~~~~~~~~~~
    \draw[red] (5:4.5) -- (10:2.5) -- (20:1.2)
            -- (30:1) -- (40:.9) -- (50:.9)
            -- (60:.9) -- (70:.9) -- (80:.9)
            -- (90:.9) -- (100:.9) -- (110:.9)
            -- (120:.9) -- (130:.9) -- (140:.95)
            -- (150:1) -- (160:1.5) -- (170:2.5) -- (174:5)
            ;
    \draw[orange,line width=2pt] (12:5) -- (20:3)
            -- (30:2.3) -- (40:2) -- (50:1.9)
            -- (60:1.8) -- (70:1.8) -- (80:1.8)
            -- (90:1.8) -- (100:1.8) -- (110:1.8)
            -- (120:1.8) -- (130:1.9) -- (140:2)
            -- (150:2.3) -- (160:3) -- (170:5)
            ;           

    % ~~~ (8) frame, to overwrite colors ~~~~~~~~~~~~~~~~~~
    \draw (-4,0) -- (4,0) -- (4,2) -- (-4,2) -- cycle; 
 \end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .