1

I was inspired by the graphic Moon Synodic Period, created by Tangent Plane. I insert the code here. I tried to create scale definitions, so I could scale the graph and the text, but I'm not entirely satisfied with that.

Could I ask for suggestions to optimize the code? thanks

\documentclass[a4paper,portrate]{article}
\usepackage[T1]{fontenc} 
\usepackage[italian]{babel}
\usepackage{amsmath}
\usepackage[margin=0.3in]{geometry}
\usepackage{tikz}
\usetikzlibrary{scopes}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}

\usepackage{mwe}
\usepackage{lmodern}
\makeatletter
\DeclareMathSizes{\@xpt}{\@xpt}{5}{4}
\DeclareMathSizes{\@xipt}{\@xipt}{6}{5}
\DeclareMathSizes{\@xiipt}{\@xiipt}{6}{5}
\DeclareMathSizes{\@xivpt}{\@xivpt}{\@xpt}{6}
\makeatother

\begin{document}
\begin{tikzpicture} [
scale=0.5,
node font=\small,
dashed axis/.style={dash pattern=on 4pt off 2pt},
moon line/.style={dash pattern=on 8pt off 4pt},
information text/.style={rounded corners, fill=Info Color, inner sep=1ex}
]

\definecolor{Earth Color}{HTML}{358af3};
\definecolor{Sun Color}{HTML}{fffc00};
\definecolor{Moon Color}{HTML}{ddbd4c};
\definecolor{Info Color}{HTML}{eeeeee};

\def\ax{0}; %Posizione centrale assi%
\def\ay{0}
%%--Scale Factor --------------------
\def\sca{1}
\def\scaa{0.9}
% Asse x e y
\draw[{Stealth[length=0.01cm]}-{Stealth[length=0.2cm]}] (-16, 0) -- (16, 0) node [scale=\sca,right=0.1em] {$P_{G}$}; % Asse 
\draw[{Stealth[length=0.001cm]}-{Stealth[length=0.2cm]}] (0, -0) -- (0, 16) node [scale=\sca,above=0.1em] {$P_{M}$};

%%--------------------------------------------------------------------------------
\path (0, 0) node [scale=\sca,shift={(7,1)}] {CL};
\path (0, 0) node [scale=\sca,shift={(4.2,0.2)}] { $P_{G}>>P_{M}$};
\path (0, 0) node [scale=\sca,shift={(4.5, 4)}, anchor=north west] {CM};
\path (0, 0) node [scale=\sca,shift={(2.5, 3)}, anchor=north west] {$P_{M}\approx P_{G}$};
\path (0, 0) node [scale=\sca,shift={(0,7)},draw=black,fill=white] {CF};
\path (0, 0) node [scale=\sca,shift={(0,6)},draw=black,fill=white] {$P_{M}>>P_{G}$};
\path (0, 0) node [scale=\sca,shift={(0,5)},draw=black,fill=white] {$R_{i}=0$};
\path (0, 0) node [scale=\sca,shift={(-4.5, 4)}, anchor=north west] {TFS};
\path (0, 0) node [scale=\sca,shift={(-4.5, 3)}, anchor=north west] {$P_{M}>0,P_{G}<0$};
\path (0, 0) node [scale=\sca,shift={(-7,1)}] {FS};
\path (0, 0) node [scale=\sca,shift={(-4.2,0.2)}] { $P_{M}\approx 0,P_{G}<0$};
%------------------------------------------------------------------------------------
\path (0, 0) node [scale=\sca,shift={(6.5,0)},draw=black,fill=white] {$R_{i}=+\infty$};
\path (0, 0) node [scale=\sca,shift={(-6.5,0)},draw=black,fill=white] {$R_{i}=+\infty$};
%
\begin{scope}[rotate around={-75:(0, 0)}]
\draw[{Stealth[length=0.01cm]}-{Stealth[length=0.01cm]}] (0, -0) -- (0, 15) node [scale=\sca,rotate = 45, above=-1em] {};
\end{scope}

\begin{scope}[rotate around={75:(0, 0)}]
\draw[-] (0, -0) -- (0, 15) node [ rotate = -15, right = 20,left=0.5em] {};
\end{scope}

\path (0, 0) node [scale=\sca,shift={(-3.7,1)}, draw=black,fill=white,rotate = -15] {$R_{i}\approx+1$};
\path (0, 0) node [scale=\sca,shift={(3.7,1)}, draw=black,fill=white,rotate = 15] {{ $ R_{i}\approx-1$}};

% draw line
\begin{scope}[rotate around={-20:(0, 0)}]
\draw[moon line] (0, 0) -- (0, 15);
\node [shift={(-0.8,1)}] at (0, 7) {};];
\end{scope}
% draw line
\begin{scope}[rotate around={20:(0, 0)}]
\draw[moon line] (0, 0) -- (0, 15);
\end{scope}


\foreach \i in {5,...,1}
{
    \pgfmathparse{(160/3.8)*(\i)-396};
    \node[scale=\sca] at (\pgfmathresult:5cm) {\i};
};

%draw information box
\draw[shift={(6, 10)}] node[scale=\scaa,above right, text width=4cm,information text] {
    \small
    {\boldmath
        \textbf{\underline{Indice}} }
    \vspace{1ex}
    \small
    \begin{description}
    {\boldmath
        \item[CL]: Libera;
        \item[CM]: Mista;
        \item[CF]: Forzata;
        \item[TFS]: Turbolenza in FS;
        \item[FS]: Flussi Stratificati;
    }
    \end{description}
};
\node[scale=\sca,above right] at (-3, -1.2) {\textbf{Fig. 1} \hspace{0.1cm} TKE};

\end{tikzpicture}

%\end{tikzpicture}


\end{document}

enter image description here

Antonio
  • 543
  • Two obvious things: adding scale=\sca, does not have any effect given that \sca is 1, and instead of hardcoding the figure number use the caption package. –  May 02 '19 at 17:37
  • @marmot when I vary, the general scale, \sca and \scaa, varies the whole figure correctly. I have already performed several tests. the code can be improved, but I am not very familiar with the package. As for the package caption, I know, this is just a test and an exercise – Antonio May 02 '19 at 18:15

1 Answers1

4

This is an attempt to simplify some things. I got rid of all the rotate arounds in favor of polar coordinates and the sloped key, empty nodes, several explicit coordinates and so on. If you want to scale all nodes by a factor, you can add simply every node/.append style={scale=\sca} to the options of the tikzpicture. Also use \gg instead of >> and so on. This is by no means a fully optimized code but perhaps a step in this direction.

\documentclass[a4paper,portrate]{article}
\usepackage[T1]{fontenc} 
\usepackage[italian]{babel}
\usepackage{amsmath}
\usepackage{caption}
\usepackage[margin=0.3in]{geometry}
\usepackage{tikz}
\usetikzlibrary{scopes}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}

\usepackage{lmodern}
\makeatletter
\DeclareMathSizes{\@xpt}{\@xpt}{5}{4}
\DeclareMathSizes{\@xipt}{\@xipt}{6}{5}
\DeclareMathSizes{\@xiipt}{\@xiipt}{6}{5}
\DeclareMathSizes{\@xivpt}{\@xivpt}{\@xpt}{6}
\makeatother
\captionsetup[figure]{labelfont=bf}
\begin{document}
\begin{tikzpicture} [scale=0.5,
node font=\small,
dashed axis/.style={dash pattern=on 4pt off 2pt},
moon line/.style={dash pattern=on 8pt off 4pt},
information text/.style={rounded corners, fill=Info Color, inner sep=1ex},
prg/.style={draw,fill=white}
]

\definecolor{Earth Color}{HTML}{358af3};
\definecolor{Sun Color}{HTML}{fffc00};
\definecolor{Moon Color}{HTML}{ddbd4c};
\definecolor{Info Color}{HTML}{eeeeee};

\def\ax{0}; %Posizione centrale assi%
\def\ay{0}
%%--Scale Factor --------------------
\def\sca{1}
\def\scaa{0.9}
% Asse x e y
\draw[{Stealth[length=0.01cm]}-{Stealth[length=0.2cm]}] (-16, 0) -- (16, 0) 
node [right=0.1em] {$P_{G}$} 
node[pos=2/32,above=0.8cm]{FS}
node[pos=1/4,above=3.8cm]{$P_{M}>0,P_{G}<0$}
node[pos=1/4,above]{$P_{M}\approx 0,P_{G}<0$}
node[pos=24.4/32,above]{$P_{G}\gg P_{M}$}
node[pos=30/32,above=0.8cm]{CL}
{[nodes=prg]  node[pos=0.1]{$R_{i}=+\infty$}
node[pos=0.9]{$R_{i}=+\infty$}}; % Asse 
\draw[{Stealth[length=0.001cm]}-{Stealth[length=0.2cm]}] (0, -0) -- (0, 16) 
node [above=0.1em] {$P_{M}$}
{[nodes=prg] node[pos=14/16]{CF} node[pos=12/16]{$P_{M}\gg P_{G}$}
node[pos=10/16] {$R_{i}=0$}};

%%--------------------------------------------------------------------------------
\path (2.5, 3)node [anchor=north west] {$P_{M}\approx P_{G}$}
(-4.5, 4) node [anchor=south east] {TFS};
%------------------------------------------------------------------------------------
%
\draw[{Stealth[length=0.01cm]}-{Stealth[length=0.01cm]}] (0, -0) -- (15:15) 
node[prg,midway,sloped]{ $ R_{i}\approx-1$};

\draw[-] (0, -0) -- (165:15) node[prg,midway,sloped] {$R_{i}\approx+1$};

\draw[moon line] (110:15) -- (0, 0) -- (70:15);


\foreach \i in {5,...,1}
{
    \node at ({(160/3.8)*(\i)-396}:5cm) {\i};
};

%draw information box
\draw[shift={(6, 10)}] node[scale=\scaa,above right, text width=4cm,information text] {
    \small
    {\boldmath
        \textbf{\underline{Indice}} }
    \vspace{1ex}
    \small
    \begin{description}
        \item[CL]: Libera;
        \item[CM]: Mista;
        \item[CF]: Forzata;
        \item[TFS]: Turbolenza in FS;
        \item[FS]: Flussi Stratificati;
    \end{description}
};
\node[anchor=north,align=center,text width=4cm] at (0,-0.2) {\captionof{figure}{TKE.}};

\end{tikzpicture}

\end{document}

enter image description here

  • Very well, thank you. there is always something to learn. I imagine we can find other solutions. I have inserted the line [scale = 0.5, every node/.append style={scale=1},....... to the options. in this way I get both the graph scale and the text scale. – Antonio May 03 '19 at 09:07