加热斜坡图,增加和减少轴

加热斜坡图,增加和减少轴

首先我要澄清的是,我不知道如何用英语正确地命名这个,所以请随意编辑标题或发表评论。

我需要以一种方式绘制这些数据,使加热和冷却(Tr)显示在同一轴上,并且同一方向。见图。我找不到让 x 轴转到 900 然后再减小回来的方法,同时仍然从左到右移动。

如果我按时间(t)绘图,我才能得到所需的结果,但是,我需要一个显示温度的轴。

我曾尝试将其分成两个图并进行镜像,但这样会花费我太多时间,因为以后再处理其他类似的图时会花费太多时间。此外,在曲线复杂的情况下,效果也不太优雅,视觉效果也不太好。

在此处输入图片描述

\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}

答案1

这将温度作为时间函数添加到上方的 x 轴上。由于温度不等距,因此会抑制某些刻度,否则它们会重叠。最小距离编码为

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

还请注意,数据文件中以 开头的行13984只有 5 个元素。我添加了一个元素。运行此代码时,请确保您确实用原始数据集覆盖了数据文件,否则您将收到错误unbalanced columns

\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}

在此处输入图片描述

相关内容