Rice University logo
 
Top blue bar image
 

Two images generated using latex packages tikz and pgfplots

The following images were generated by tikz and pgfplots scripts in latex.

  

The Latex source file is:

\documentclass{article}

\usepackage{tikz, pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize[prefix=figures/]

\begin{document}

\thispagestyle{empty}

\tikzsetnextfilename{L1_ball_fig} % general PDF image L1_ball_fig.pdf
\begin{tikzpicture}[scale=0.5]
   \begin{axis}[hide axis, view={125}{25}, axis equal=true]

        % 3 axes
        \addplot3[thin,dotted,->] coordinates {(-2.4,0,0) (3.0,0,0)};
        \addplot3[thin,dotted,->] coordinates {(0,-2.4,0) (0,3.0,0)};
        \addplot3[thin,dotted,->] coordinates {(0,0,-2.4) (0,0,3.0)};

        % L1 ball boundaries
        \addplot3[thin,domain=0:4/3, samples y=0] (x,0,4/3-x);
        \addplot3[thin,domain=0:4/3, samples y=0] (x,0,x-4/3);

        \addplot3[domain=0:4/3, samples y=0] (0,x,4/3-x);
        \addplot3[domain=0:4/3, samples y=0] (0,x,x-4/3);

        \addplot3[domain=-4/3:0, samples y=0] (x,0,4/3+x);
        \addplot3[dashed, domain=-4/3:0, samples y=0] (x,0,-x-4/3);

        \addplot3[domain=-4/3:0, samples y=0] (0,x,4/3+x);
        \addplot3[dashed, domain=-4/3:0, samples y=0] (0,x,-x-4/3);

        % horizontal lines
        \addplot3[domain=0:4/3, samples y=0] (4/3-x,x,0);
        \addplot3[domain=0:4/3, samples y=0] (x-4/3,x,0);
        \addplot3[dashed, domain=-4/3:0, samples y=0] (-4/3-x,x,0);
        \addplot3[domain=-4/3:0, samples y=0] (4/3+x,x,0);

        % Ax = b
        \addplot3[red,domain=-1.6:3.0, samples y=0] ({(2-x)*1/3},{-(2-x)*1/3},x);

    	% intersection points
    	\addplot3[only marks, mark size=2pt, blue] coordinates{(0,0,2)} node [left] {$\mathbf{x}^o$};
    	\addplot3[only marks, mark size=2pt] coordinates{(2/3,-2/3,0)};
   \end{axis}
\end{tikzpicture}

\tikzsetnextfilename{L05_ball_fig} % general PDF image L05_ball_fig.pdf
\begin{tikzpicture}[scale=0.5]
%   \begin{axis}[xmin=-2, xmax=3, ymin=-2, ymax=3, zmin=-2, zmax=3, hide axis, view={135}{35}, plot box ratio=1 1 2]
   \begin{axis}[hide axis, view={125}{25}, axis equal=true]

        % 3 axes
        \addplot3[thin,dotted,->] coordinates {(-2.2,0,0) (2.8,0,0)};
        \addplot3[thin,dotted,->] coordinates {(0,-2.2,0) (0,2.8,0)};
        \addplot3[thin,dotted,->] coordinates {(0,0,-2.2) (0,0,2.8)};

        % Ax = b
        \addplot3[red,domain=-1.6:3.0, samples y=0] ({(2-x)*1/3},{-(2-x)*1/3},x);

        % L_1/2 ball boundaries
        \addplot3[domain=0:4/2, samples y=0] (x,0,{(sqrt(4/2)-sqrt(x))^2});
        \addplot3[domain=0:4/2, samples y=0] (x,0,-{(sqrt(4/2)-sqrt(x))^2});

        \addplot3[domain=0:4/2, samples y=0] (0,x,{(sqrt(4/2)-sqrt(x))^2});
        \addplot3[domain=0:4/2, samples y=0] (0,x,-{(sqrt(4/2)-sqrt(x))^2});

        \addplot3[domain=-4/2:0, samples y=0] (x,0,{(sqrt(4/2)-sqrt(-x))^2});
        \addplot3[dashed, domain=-4/2:0, samples y=0] (x,0,-{(sqrt(4/2)-sqrt(-x))^2});

        \addplot3[domain=-4/2:0, samples y=0] (0,x,{(sqrt(4/2)-sqrt(-x))^2});
        \addplot3[dashed, domain=-4/2:0, samples y=0] (0,x,-{(sqrt(4/2)-sqrt(-x))^2});

        % connection lines
        \addplot3[domain=0:4/2, samples y=0] ({(sqrt(4/2)-sqrt(x))^2},x,0);
        \addplot3[domain=0:4/2, samples y=0] (-{(sqrt(4/2)-sqrt(x))^2},x,0);
        \addplot3[dashed, domain=-4/2:0, samples y=0] (-{(sqrt(4/2)-sqrt(-x))^2},x,0);
        \addplot3[domain=-4/2:0, samples y=0] ({(sqrt(4/2)-sqrt(-x))^2},x,0);

    	% intersection points
    	\addplot3[only marks, mark size=2pt, blue] coordinates{(0,0,2)} node [left] {$\mathbf{x}^o$};

   \end{axis}
\end{tikzpicture}

\end{document}

To typeset this latex, I used pdflatex with the switch -shell-escape (or -enable-write18 in MikTex). I also used the tools in this blog to crop the white space around the plots.

Comments are closed.