Re: Stile grafico – pgfplots

#85361
Up
0
Down
::

Marco87″ post=84788Ciao a tutti,

nella mia tesi devo riprodurre un grafico così come si presenta in un articolo (premetto che la resa grafico non è eccellente). Il codice che ho scritto è questo:
`\documentclass[a4paper,11pt]{memoir}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}

\usepackage{amsmath,amssymb,siunitx}

\usepackage{tikz}
\usetikzlibrary{hobby}
\ExplSyntaxOn
\cs_if_exist:NF \prg_stepwise_function:nnnN { \cs_gset_eq:NN \prg_stepwise_function:nnnN \int_step_function:nnnN }
\cs_if_exist:NF \prg_stepwise_inline:nnnn { \cs_gset_eq:NN \prg_stepwise_inline:nnnn \int_step_inline:nnnn }
\ExplSyntaxOff

\usepackage{pgfplots}

\pgfplotsset{compat=1.8}

\pgfplotsset{
stileNormale/.style={
/pgfplots/width=.85\columnwidth,
/pgfplots/height=.75\columnwidth,
enlargelimits,
/pgfplots/grid=major,
/pgfplots/axis lines=middle,
/pgfplots/xminorgrids=true,
every axis x label/.style=
{at={(ticklabel cs:0.5)},anchor=near ticklabel},
every axis y label/.style=
{at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel},
legend style={font=\footnotesize},
/pgfplots/legend cell align=left,
}
}

\begin{document}
\begin{tikzpicture}
\def\xmax{3}
\def\ymax{5}
\pgfmathsetmacro{\xl}{.95*\xmax}
\pgfmathsetmacro{\yl}{.95*\ymax}
\begin{axis} [stileNormale,
disabledatascaling,
xmin=-.5,xmax=\xmax,
ymin=0,ymax=\ymax,
grid=major,
xlabel={$w_2$ \unit{(cm)}},
ylabel={$\sigma_2$ \unit{(MPa)}},
]

\draw [thick] (-.2,0) — (-.19,4.13) arc (180:270:.12 and .98) — +(.015,0);
\node at (-.06,3.15) [above] {5};

\draw [thick] (-.1,0) — (-.09,3.14) arc (180:270:.12 and 1.14) — +(.035,0);
\node at (.1,2)

{4};

\draw [thick] (-.05,0) — (-.04,2.58) arc (180:270:.2 and 1.32) — +(.12,-.001);
\node at (.265,1.259)

{3};

\draw [thick] (0,0) — (0,1.71) [out angle=275, in angle=180, curve through={(.2,.55) .. (.51,.455)}] to (.98,.45);
\node at (.98,.45)

{2};

\draw [thick] (0,1.71) [out angle=271, in angle=180, curve through={(.22,.26) .. (.5,.12)}] to (2.12,.025);
\node at (2.12,.025) [above] {1};

\node at (\xl,\yl) [anchor=north east, fill=white, align=left, inner sep=3pt, draw] {1$\quad l = \num{1.5}$, $\sigma_1 = \num{0}$ \\ 2$\quad l = \num{1.5}$, $\sigma_1 = -\num{.1}$ \\ 3$\quad l = \num{1.5}$, $\sigma_1 = -\num{.5}$ \\ 4$\quad l = \num{1.5}$, $\sigma_1 = -\num{1}$ \\ 5$\quad l = \num{1.5}$, $\sigma_1 = -\num{2}$};

\end{axis}
\end{tikzpicture}
\end{document}`
Come potete notare l’etichetta dell’asse y e i numeri della griglia di quell’asse vengono riportati a sinistra dell’asse y. Non riesco a capire come fare in modo che invece siano a sinistra del bordo sinistro del grafico (nell’esempio, l’asse x=-0.5) sempre mantenendo l’opzione [tt]axis lines=middle.[/tt] Qualcuno può aiutarmi?

Grazie mille e buona giornata,
Marco.

Dovresti cavartela con qualcosa tipo: `
yticklabel style={xshift=-0.75cm}
` Ah: tutti quei [tt]/pgfplots/[/tt] sono inutili perché il compito di [tt]\pgfplotsset[/tt] è proprio quello di impostare il path principale delle chiavi. È definito infatti con: `
\def\pgfplotsset#{\pgfqkeys{/pgfplots}}
` in [tt]pgfplotscore.code.tex[/tt]. Quindi lo stile dovrebbe diventare: `
\pgfplotsset{
stileNormale/.style={
width=.85\columnwidth,
height=.75\columnwidth,
enlargelimits,
grid=major,
axis lines=middle,
xminorgrids=true,
every axis x label/.style=
{at={(ticklabel cs:0.5)},anchor=near ticklabel},
every axis y label/.style=
{at={(ticklabel cs:0.5)},rotate=90,anchor=near ticklabel},
legend style={font=\footnotesize},
legend cell align=left,
yticklabel style={xshift=-0.75cm},
}
}
`

Ciao
Claudio

Go to top