Gráfico de rampa de calefacción, eje creciente y decreciente.

Gráfico de rampa de calefacción, eje creciente y decreciente.

Primero déjame aclarar que no sé cómo nombrar esto correctamente en inglés, así que siéntete libre de editar el título o dejar un comentario.

Necesito trazar estos datos de manera que la calefacción y la refrigeración (Tr) se muestren en el mismo eje ymisma dirección. Ver imagen. No pude encontrar una manera de hacer que el eje x vaya a 900 y luego disminuya hacia atrás, mientras sigo yendo de izquierda a derecha.

Solo puedo obtener el resultado deseado si trazo por el tiempo (t), sin embargo, necesito un eje que muestre la temperatura.

Intenté dividir en dos tramas y reflejarlas, pero eso me llevaría demasiado tiempo con otras tramas como esta en el futuro. Aparte de no ser demasiado elegante y el aspecto visual dista mucho de ser bueno en el caso de una curva complicada.

ingrese la descripción de la imagen aquí

\documentclass[]{standalone}

    % UNITS
\usepackage{siunitx}
\sisetup{per-mode=fraction, abbreviations}

    % GRAPHICS
\usepackage{pgfplots}
\pgfplotsset{width=9cm,height=6cm,compat=newest}

% Style to select only points from #1 to #2 (inclusive)
\pgfplotsset{select coords between index/.style 2 args={
        x filter/.code={
            \ifnum\coordindex<#1\def\pgfmathresult{}\fi
            \ifnum\coordindex>#2\def\pgfmathresult{}\fi
        }
}}

\usepackage{filecontents}

\begin{filecontents}{datax.dat}
t,HF,Gewicht,Normal,DTG,Tr
574,1.20838,8.47718,0.981320918,-0.00509898,67.8333
3794,27.9521,2.06633,0.239198985,-0.009580838,372.333
6944,6.17274,0.420004,0.04861979,0,897.333
6964,3.65761,0.419016,0.048505419,0,900 
7424,-19.0714,0.413001,0.047809121,0,900
13984,-28.3111,0.367016,0.0424858830,900    
15194,-4.02426,0.321001,0.037159173,0,727.667
17074,28.3149,0.190241,0.022022356,0,414.333
18914,13.0023,-0.164632,-0.01905785,0,107.667
\end{filecontents}

\begin{document}
{\footnotesize 
\begin{tikzpicture}
    \bigskip

\pgfplotsset{
scale only axis,
minor x tick num=3,
}

\begin{axis}[
axis y line*=left,
ymin=-0.1, ymax=1.1,
minor y tick num=4,
xlabel=Time (\si{\second}),
%xlabel=Temperature (\si{\degreeCelsius}),
ylabel=\ref{TGA} Mass ($\%$),
,
]
\addplot [smooth,thick,cyan,] table [,x=t, y=Normal, col sep=comma] {datax.dat};
\label{TGA}
\end{axis}

\begin{axis}[
axis y line*=right,
minor y tick num=4,
ylabel=\ref{DTG} Derivative Mass ($\% /\ \si{\degreeCelsius}$),
]
\addplot [smooth,thick,dashed,green!60!black,] table [x=t, y=HF, col sep=comma] {datax.dat};
\label{DTG};
\end{axis}
\end{tikzpicture}
}
\end{document}

Respuesta1

Esto suma la temperatura en función del tiempo en el eje x superior. Dado que las temperaturas no son equidistantes, algunas garrapatas se suprimen, ya que de lo contrario se superpondrían. La distancia mínima está codificada en

\pgfmathtruncatemacroFPU{\itest}{ifthenelse(abs(\Time/10000-\LastTime/10000)>0.1,1,0)}%

Tenga en cuenta también que la fila que comienza 13984en su archivo de datos solo tiene 5 elementos. Agregué un elemento. Cuando ejecute este código, asegúrese de sobrescribir realmente el archivo de datos; con su conjunto de datos original obtendrá un unbalanced columnserror.

\documentclass[]{standalone}

    % UNITS
\usepackage{siunitx}
\sisetup{per-mode=fraction, abbreviations}

    % GRAPHICS
\usepackage{pgfplots}
\pgfplotsset{width=9cm,height=6cm,compat=newest}

% Style to select only points from #1 to #2 (inclusive)
\pgfplotsset{select coords between index/.style 2 args={
        x filter/.code={
            \ifnum\coordindex<#1\def\pgfmathresult{}\fi
            \ifnum\coordindex>#2\def\pgfmathresult{}\fi
        }
}}

\usepackage{filecontents}

\begin{filecontents*}{datax.dat}
t,HF,Gewicht,Normal,DTG,Tr
574,1.20838,8.47718,0.981320918,-0.00509898,67.8333
3794,27.9521,2.06633,0.239198985,-0.009580838,372.333
6944,6.17274,0.420004,0.04861979,0,897.333
6964,3.65761,0.419016,0.048505419,0,900 
7424,-19.0714,0.413001,0.047809121,0,900
13984,-28.3111,0.367016,0.0424858830,0,900    
15194,-4.02426,0.321001,0.037159173,0,727.667
17074,28.3149,0.190241,0.022022356,0,414.333
18914,13.0023,-0.164632,-0.01905785,0,107.667
\end{filecontents*}

\newcommand*{\ReadOutElement}[4]{%
    \pgfplotstablegetelem{#2}{[index]#3}\of{#1}%
    \let#4\pgfplotsretval
}
\def\pgfmathtruncatemacroFPU#1#2{\begingroup%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\pgfmathtruncatemacro{#1}{#2}%
\pgfmathsmuggle#1\endgroup}%

\begin{document}

{\footnotesize%<- am not sure about this one
\begin{tikzpicture}
\pgfplotstableread[header=true,col sep=comma]{datax.dat}{\datatable}%   
\pgfplotstablegetrowsof{\datatable}%
\pgfmathtruncatemacro{\numrows}{\pgfplotsretval}%
\pgfplotsforeachungrouped \iloop in {0,...,\the\numexpr\numrows-1}
{\ReadOutElement{\datatable}{\iloop}{0}{\Time}%
 \ReadOutElement{\datatable}{\iloop}{5}{\Temp}%
 \pgfmathtruncatemacro{\Temp}{\Temp}%
 \ifnum\iloop=0
  \edef\LstTimes{\Time}
  \edef\LstTemps{\Temp}
  \edef\LastTime{\Time}
 \else
  \pgfmathtruncatemacroFPU{\itest}{ifthenelse(abs(\Time/10000-\LastTime/10000)>0.1,1,0)}%
  \ifnum\itest=1
   \edef\LstTimes{\LstTimes,\Time}
   \edef\LstTemps{\LstTemps,\Temp}
   \edef\LastTime{\Time}
  \fi
 \fi}
 %\pgfmathsetmacro{\LstTemps}{{\LstTemps}[0]}
% \show\LstTemps
 %\typeout{\LstTimes,\LstTemps}

\pgfplotsset{
scale only axis,
minor x tick num=3,
}

\begin{axis}[
axis y line*=left,
ymin=-0.1, ymax=1.1,
minor y tick num=4,
xlabel=Time (\si{\second}),
ylabel=\ref{TGA} Mass ($\%$),
,
]
\addplot [smooth,thick,cyan,] table [,x=t, y=Normal, col sep=comma] {datax.dat};
\label{TGA}
\end{axis}

\begin{axis}[
axis y line*=right,
minor y tick num=4,
axis x line*=right,scaled ticks = false,
xlabel={Temperature (\si{\degreeCelsius})},
xtick=\LstTimes,xticklabels/.expanded=\LstTemps,
%xticklabel style={/pgf/number format/precision = 0},
ylabel=\ref{DTG} Derivative Mass ($\% /\ \si{\degreeCelsius}$),
]
\addplot [smooth,thick,dashed,green!60!black,] table [x=t, y=HF, col sep=comma] {datax.dat};
\label{DTG};
\end{axis}
\end{tikzpicture}
}
\end{document}

ingrese la descripción de la imagen aquí

información relacionada