1

This question already has an answer here:

I want to draw these shapes, would u please help me? thanks a lot. Different norms

@peter It is so useful, thanks a lot for your attention, but actually I want to draw this figure, sorry for inconvenience I am a little amateur. enter image description here

marked as duplicate by percusse, Mensch, user31729, user13907, Torbjørn T. Aug 13 '14 at 14:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    Have a look at TikZ. Can you show us with a MWE, what you have tried until now? – Hackbard_C Aug 13 '14 at 9:20
  • 3
    In addition: Because Tikz is a very large LaTeX package, I would recommend to read an introduction/tutorial, first. It helps to get a first impression how to use it. For example, Graphics with TikZ and A very minimal introduction to TikZ look moderate. After this, I would take a look into the official documentation. The graphics you want to create are perfect in the beginning! Good luck! – dawu Aug 13 '14 at 9:26
  • 1
    You can find a similar question here: tex.stackexchange.com/questions/191518/… – Ignasi Aug 13 '14 at 9:30
  • 1
    You also can take a look at pstricks and pst-plot, which are very well documented. They can be compiled with pdflatexif you load your document class with option pdf, provided odflatex is launched with the --shell-escape switch (TeX Live, MacTeX) or --enable-write18 (MiKTeX). – Bernard Aug 13 '14 at 9:32
  • 2
    What is the general equation for the figures, i.e., the equation involving p? – Svend Tveskæg Aug 13 '14 at 10:23
7

This is another boring after noon with some free time. To explain code, it will be terribly boring though!

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw [<->] (-4,0)--(4,0);
\draw [<->] (0,-4)--(0,4);
\draw[blue] (-3,0) -- (0,3) -- (3,0) -- (0,-3) -- (-3,0);
\node at (0,-4.5) {$p=1$};
\end{tikzpicture}
\begin{tikzpicture}
\draw [<->] (-4,0)--(4,0);
\draw [<->] (0,-4)--(0,4);
\draw[blue] (0,0) circle[x radius=3cm,y radius=2.6cm];
\node at (0,-4.5) {$p=2$};
\end{tikzpicture}
\begin{tikzpicture}
\draw [<->] (-4,0)--(4,0);
\draw [<->] (0,-4)--(0,4);
\draw[blue] (-3,-3) rectangle (3,3);
\node at (0,-4.5) {$p=\infty$};
\end{tikzpicture}
\begin{tikzpicture}
\draw [<->] (-4,0)--(4,0);
\draw [<->] (0,-4)--(0,4);
\draw[blue] (-3,0) 
            to[bend right] (0,3) 
            to[bend right] (3,0) 
            to[bend right] (0,-3) 
            to[bend right] (-3,0);
\node at (0,-4.5) {$p=\frac{1}{2}$};
\end{tikzpicture}
\end{document}

enter image description here

  • @peter It is so useful, thanks a lot for your attention, but actually I want to draw this figure, sorry for inconvenience I am a little amateur. – hamed Aug 13 '14 at 12:49
4

Unit balls so why not pgfplots?

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=middle,xtick=\empty,ytick=\empty,axis equal,enlargelimits,xmax=1,ymax=1,xmin=-1,ymin=-1]
%p=0.5
\begin{scope}[very thick,dotted,orange,domain=0:pi,samples=50]
\addplot[] ({(cos(deg(x)))^(4},{ (sin(deg(x))^(4});
\addplot[] ({(cos(deg(x)))^(4},{ -(sin(deg(x))^(4});
\addplot[] ({-(cos(deg(x)))^(4},{ (sin(deg(x))^(4});
\addplot[] ({-(cos(deg(x)))^(4},{-(sin(deg(x))^(4});
\end{scope}
%p=1
\addplot[blue,domain=0:pi] ({(cos(deg(x)))^2},{(sin(deg(x))^2});
\addplot[blue,domain=0:pi] ({(cos(deg(x)))^2},{-(sin(deg(x))^2});
\addplot[blue,domain=0:pi] ({-(cos(deg(x)))^2},{(sin(deg(x))^2});
\addplot[blue,domain=0:pi] ({-(cos(deg(x)))^2},{-(sin(deg(x))^2});
%p=2
\addplot[red,domain=-pi:0] ({(cos(deg(x)))},{(sin(deg(x))});
\addplot[red,domain=0:pi] ({(cos(deg(x)))},{(sin(deg(x))});
%p=inf
\draw[thick,dashdotted,gray] (axis cs:-1,-1) rectangle (axis cs:1,1);
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

4

This one is just a modification of percusse's answer, to use loops instead of having big chunks of code:

\documentclass[border=3mm]{standalone}

\usepackage{pgfplots}

% Unit circle plot style
\pgfplotsset{unit circle/.style={width=4cm,height=4cm,axis lines=middle,xtick=\empty,ytick=\empty,axis equal,enlargelimits,xmax=1,ymax=1,xmin=-1,ymin=-1,domain=0:pi/2}}

\begin{document}
    \begin{tikzpicture}
    \coordinate (prev); % Store previous plot position
    \foreach \p / \t in {4/\frac{1}{2}, 2/1, 1/2, 0.0001/\infty} { % Loop through the plots to draw
        % \p is the exponent in the function to plot
        % \t is the p parameter to print
        \begin{axis}[at={(prev)},unit circle,anchor=west]
            \foreach \ss in {1,-1} {
            \foreach \cs in {1,-1} {
                \addplot[] ({\cs*(cos(deg(x)))^\p},{\ss*(sin(deg(x))^\p});
            }
            }
        \end{axis}
        \node[below=0.5cm, anchor=base] at (current axis.south) {$p=\t$}; % Print p
        \coordinate[right=0.5cm] (prev) at (current axis.east) ; % Set position for next plot
    }
    \end{tikzpicture}
\end{document}

EDIT: As noted by percusse, this solution is a bit cheating to draw the unit circle for the maximum norm, approximating it with the 20000-norm. I believe it looks good enough, though. Also, every unit circle is drawn with 4 plots, even when only one could do.

If you want other p-norm to be drawn, just add them to the list. The exponent \p should be a numerical value equal (or close) to 2/p, and \t a printable representation of p.

rendering

  • still, very nice :) – percusse Aug 13 '14 at 13:39
  • @TonioELGringo your help is so worthy, would you please check edited question and answer it? – hamed Aug 13 '14 at 16:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.