0

I'm dealing with this kind of file .dat

   t1a      psi1a          t1b      psi1b          t1c      psi1c           t2       psi2           t3       psi3
 0.000   95.32842        0.000   99.37904        0.000   93.80294        0.000   89.99999        0.000    0.00000
 0.234   95.15137        0.199   99.11545        0.252   93.66990        0.135   89.82256        0.103    0.00000
 0.468   94.97408        0.397   98.85091        0.505   93.53677        0.270   89.64513        0.206    0.00000
 0.703   94.79656        0.596   98.58542        0.757   93.40355        0.405   89.46770        0.309    0.00000
 0.937   94.61880        0.795   98.31898        1.009   93.27024        0.540   89.29029        0.412    0.00000
 1.171   94.44080        0.994   98.05160        1.261   93.13684        0.675   89.11289        0.514    0.00000
 1.405   94.26258        1.192   97.78329        1.514   93.00335        0.810   88.93551        0.617    0.00000
 1.640   94.08413        1.391   97.51405        1.766   92.86977        0.945   88.75814        0.720    0.00000
 1.874   93.90546        1.590   97.24389        2.018   92.73610        1.080   88.58080        0.823    0.00000
 2.108   93.72658        1.789   96.97283        2.270   92.60235        1.215   88.40349        0.926    0.00000
 2.342   93.54747        1.987   96.70086        2.523   92.46852        1.350   88.22621        1.029    0.00000
 2.577   93.36815        2.186   96.42799        2.775   92.33460        1.485   88.04897        1.132    0.00000
 2.811   93.18862        2.385   96.15423        3.027   92.20060        1.620   87.87176        1.235    0.00000
 3.045   93.00889        2.584   95.87960        3.279   92.06653        1.755   87.69459        1.338    0.00000

And to get a plot I'm using \pgfplots environment. Here a MWE:

\documentclass{article}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor} %color extension

\usepackage{pgf,pgfplots,pgfplotstable} \pgfplotsset{compat=newest} \usepgfplotslibrary{colormaps} \begin{document} \begin{figure} \centering \pgfplotstableread{data/psi/psit.dat}{\table}

\begin{tikzpicture}
\begin{axis}[
    title = Time evolution of thrust angle $\psi$ along the trajectory,
    xmin = 0, xmax = 27,
    ymin = -0.5, ymax = 105,
    xtick distance = 5,
    ytick distance = 30,
    xlabel={$time\;[s]$},
    ylabel={$\boldsymbol{\psi}\;[\circ]$},
    grid = both,
    grid style = {dotted},
    minor tick num = 1,
    major grid style = {lightgray!75},
    minor grid style = {lightgray!75},
    width = 0.85\textwidth,
    height = 0.50\textwidth,
    %scale only axis,
    legend cell align = {left},
    legend pos = south east
]

\addplot[smooth, black, very thick] table [x = {t1a}, y = {psi1a}] {\table};
\addplot[smooth, Lavender, very thick] table [x = {t1b}, y = {psi1b}] {\table};
\addplot[smooth, Violet, very thick] table [x = {t1c}, y = {psi1c}] {\table};
\addplot[smooth, Emerald, very thick] table [x = {t2}, y = {psi2}] {\table};
\addplot[smooth, Melon, very thick] table [x = {t3}, y = {psi3}] {\table};

\legend{
n1 (k),
n1 (k+2),
n1 (k-2),
n2,
n3,  
}

\end{axis} \end{tikzpicture} \caption{Thrust angle $\psi$ as a function of time}

\end{figure} \end{document}

I would like to know how I could make dashed lines within each plot in a specific domain of t1a, t1b, t1c, t2 and t3, leaving the rest of the domain with a solid line. For istance I would like to have dashed lines in correspondence of:

t1a=0.937:1.874
t1b=1.192:2.186
t1c=0.757:2.018
t2=0:1.485
t3=0:1.132 

I've tried the dashed option, splitting a single plot in three different plots by setting a specific domain for each one, but I don't know if there is a better option. Anyway with my current solution the code messes up with the legend, because it considers three different curves instead of just one.

I hope someone can help me, thank you.

Catarella
  • 361
  • 3
    You can read about the forget plot option many places e.g. here: https://tex.stackexchange.com/questions/14506/pgfplots-prevent-single-plot-from-being-listed-in-legend – hpekristiansen Jun 08 '21 at 14:13
  • 1
    Unrelated: I would recommend using a different macro than \table, e.g., \DataTable. Had you placed that \pgfplotstableread outside the figure environment, you would have broken the table environment, because \begin{table} actually does \table. Also, please make complete examples, containing all necessary packages and definitions. It just makes it a lot easier for anyone wanting to test your example if they don't have to figure out undefined colours, macros, etc. :) – Torbjørn T. Jun 08 '21 at 14:17
  • Thank you @TorbjørnT, you are right. I'll fix the MWE in a moment . – Catarella Jun 08 '21 at 14:20
  • Hi @TorbjørnT. I'm trying to put some of the plots I've created inside specific \section of a chapter, and I don't know why they don't follow the natural order I command. Could the figure enviroment be the problem? I've updated the macro as you told me, putting \DataTable where there was \table. – Catarella Jun 11 '21 at 09:03
  • 1
    A figure is what's called a floating environment, meaning it can (and most often will) move to avoid bad page breaks. See e.g. https://tex.stackexchange.com/questions/279 https://tex.stackexchange.com/questions/2275 https://tex.stackexchange.com/questions/8625 and https://tex.stackexchange.com/questions/39017 – Torbjørn T. Jun 11 '21 at 09:43
  • Great @TorbjørnT. , the first link you've given me suggest a solution that worked. Using \usepackage[section]{placeins}. I've heard about the \usepackage{float} with [H] option, but many people recommend not using it. Thank you! – Catarella Jun 11 '21 at 09:58

0 Answers0