1

The label of the first plot (added by \addlegendimage) appears in default black after two compilations which indicates that the reference of the first plot is not being resolved. Here is the code:

\documentclass[12pt,twoside,openright]{report}

\usepackage{tikz,pgfplots,float} \usepackage{csvsimple} \usepgfplotslibrary{external} \usetikzlibrary{external} \tikzexternalize \pgfplotsset{compat=newest}

\begin{document}

\begin{filecontents}{curvas_tension_DC_y_vel_desacoplamiento_OWB_Hor.csv} t;v_DC;vel_DCPM;vel_AFPM 0;0;0;0 0.5;0.5;1.25;0.125 1;1;5;1 1.5;1.5;11.25;3.375 2;2;20;8 2.5;2.5;31.25;15.625 3;3;45;27 3.5;3.5;61.25;42.875 4;4;80;64 4.5;4.5;101.25;91.125 5;5;125;125 5.5;5.5;151.25;166.375 6;6;180;216 6.5;6.5;211.25;274.625 \end{filecontents}

\begin{figure}[!ht] \centering \begin{tikzpicture} \begin{axis}[ ymin=0, ymax=6.75, xmin=0, xmax=6.75, grid, xtick={0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5}, ytick={0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5}, axis y line=left, % the '' avoids arrow heads xlabel={$t$ [s]}, xlabel near ticks, ylabel={$v_{fuente}$ [V]}, ylabel near ticks, width=\textwidth, height=0.7\textwidth, ]

\addplot[ultra thick,violet!17] table[x=t, y=v_DC,col sep=semicolon]{curvas_tension_DC_y_vel_desacoplamiento_OWB_Hor.csv}; \label{plot_one}

\end{axis}

\begin{axis}[ ymin=0, ymax=325, xmin=0, xmax=6.75, ytick={0,50,100,150,200,250,300}, hide x axis, axis y line*=right, ylabel={Velocidad [rpm]}, ylabel near ticks, width=\textwidth, height=0.7\textwidth, ]

\addlegendimage{/pgfplots/refstyle=plot_one}\addlegendentry{$v_{fuente}$}

\addplot[no markers,teal] table[x=t, y=vel_DCPM,col sep=semicolon]{curvas_tension_DC_y_vel_desacoplamiento_OWB_Hor.csv}; \addlegendentry{$n _{m , in}$};

\addplot[no markers,orange] table[x=t, y=vel_AFPM,col sep=semicolon]{curvas_tension_DC_y_vel_desacoplamiento_OWB_Hor.csv}; \addlegendentry{$n _{m , out}$};

\end{axis}

\end{tikzpicture} \end{figure}

\end{document}

Here you can find the .csv file.

For this I followed the example in the accepted answer in here.

Thanks in advance.

el_maxx
  • 163
  • 1
    Since it is your 18th question and it seems there is still confusion about MWE etc., please consider these three resources to familiarize yourself with this site: (1) https://stackoverflow.com/help/how-to-ask, (2) https://tex.stackexchange.com/tour, and (3) https://tex.meta.stackexchange.com/questions/228 (MWE). – Dr. Manuel Kuehner Nov 02 '22 at 01:48
  • 1
    Sorry, @Dr.ManuelKuehner. I will always provide an MWE from now on. – el_maxx Nov 02 '22 at 15:41
  • 1
    Thanks for the update, this makes it much easier to reproduce the issue. On that note maybe one further improvement: instead of linking to an external site for the csv file, maybe you can make the file smaller with just a few rows and columns that are needed to reproduce the problem, and then add the contents of the csv as a second code block in the question? External links can stop working at any time, and they are also a security risk. – Marijn Nov 02 '22 at 15:49
  • After adding the missing \usepackage{pgpflots} and removing the erroneous \pgfplotsset{tikz} I get https://i.stack.imgur.com/pNZpA.png, so seems like your code works fine? – Torbjørn T. Nov 02 '22 at 18:38
  • @TorbjørnT. the code that I updated does not show (to me at least) the label of plot_one in violet, but in black. Even after more than 2 compilations. – el_maxx Nov 02 '22 at 18:53
  • 1
    The code exactly as is now would throw an error because you use \pgfplotsset before \usepackage{pgfplots}. Edit: and another error because of the \FloatBarrier. – Torbjørn T. Nov 02 '22 at 18:55
  • Is there any information in the log file about errors, warnings or unresolved references? – Marijn Nov 02 '22 at 19:02
  • @Marijn Yes. This warning: LaTeX Warning: External picture `main-figure1' contains undefined references o n input line 71. ===== The previous system call resulted in undefined references inside of the o utput file. Rescheduling it for \end{document}. ======== – el_maxx Nov 02 '22 at 19:12
  • That warning is generated when you use \usepgfplotslibrary{external} and there is a problem somewhere, but this library is not loaded in the code you show here. Just to be sure: do you get that warning from this code (of course after correcting both errors that
    Torbjørn mentioned, i.e., moving \pgfplotsset one line down and removing \FloatBarrier)?
    – Marijn Nov 02 '22 at 20:12
  • @Marijn No, \usepgfplotslibrary{external} must be added. What I copied here is a fragment of other much more longer code. – el_maxx Nov 02 '22 at 20:51
  • Copying fragments is not really the idea of an MWE, for the exact reason you are seeing here: the code as provided now leads to the correct output (with a few unrelated changes), while your real problem is elsewhere (i.e., with external figures). So please provide an MWE that actually reproduces the issue, otherwise it is difficult to help you further. – Marijn Nov 02 '22 at 20:56
  • I just saw the edit, however you did not fix the two other errors mentioned (the position of \pgfplotsset and \FloatBarrier). This means the code still doesn't reproduce the issue. Please take care to test the MWE before posting/editing it. – Marijn Nov 02 '22 at 20:59
  • @Marijn I compiled on Overleaf the code I edited and it gave no error. Why does the use of \FloatBarrier lead to error? – el_maxx Nov 02 '22 at 21:13
  • 2
    \FloatBarrier is a command from the placeins package, that you didn't load in the MWE. Overleaf ignores errors by default, which often leads to incorrect output but some output is always shown if possible - maybe you missed the error message because of this. – Marijn Nov 02 '22 at 21:17

0 Answers0