如何更改刻度之间的比例

如何更改刻度之间的比例

是否可以改变两个刻度之间的间距?

4000-3000 = 3000-2000 = 2000-1500 = 1500-1000

在此处输入图片描述

\begin{tikzpicture}
\begin{groupplot}[
    group style={
        group name=my plots,
        group size=1 by 2,
        xlabels at=edge bottom,
        xticklabels at=edge bottom,
        vertical sep=0pt
    },
    width=16cm,
    height=6cm,
    xmin=400, xmax=4000,
    x dir= reverse,
    ymin=40,ymax=105,
    tickpos=left,
    xtick={500,1000,1500,2000,3000,4000},
    enlargelimits=false,
    ytick align=outside,
    xtick align=outside
]

\nextgroupplot
\addplot [smooth, black, no marks] file {data1.dat};
\nextgroupplot
\addplot [smooth, black, no marks] file {data2.dat};
\end{groupplot}
\end{tikzpicture}

例子:

在此处输入图片描述


\begin{tikzpicture}
\begin{groupplot}[
    group style={
        group name=my plots,
        group size=2 by 2,
        xlabels at=edge bottom,
        xticklabels at=edge bottom,
        vertical sep=0pt,
        horizontal sep=0pt,
    },
    height=5cm,
    x dir= reverse,
    ymin=35,ymax=105,
    tickpos=left,
    xtick align=outside
]
\nextgroupplot [xmin=2000.1, xmax=4000, width=6.9cm,ytick align=outside,axis y line*=left,xtick={3000,4000}]
\addplot [smooth, black, no marks] file {data1.dat};
\nextgroupplot [ytick=\empty,xmin=400, xmax=2000.1, width=10cm,axis y line*=right, xtick={500,1000,1500,2000}]
\addplot [smooth, black, no marks] file {data1.dat};
\nextgroupplot [xmin=2000.1, xmax=4000, width=6.9cm,ytick align=outside,axis y     line*=left,xtick={3000,4000}]
\addplot [smooth, black, no marks] file {data2.dat};
\nextgroupplot [ytick=\empty,xmin=400, xmax=2000.1, width=10cm,axis y line*=right,    xtick={500,1000,1500,2000}]
\addplot [smooth, black, no marks] file {data2.dat};
\end{groupplot}
\end{tikzpicture}

虽然不太好,但确实有效。如果有更简单的解决方案,请告诉我。

答案1

要以这种格式绘制光谱仪输出,显然是一种标准,您可以使用坐标变换。如果您设置

x coord trafo/.code={
    \pgfmathparse{#1-0.5*(#1-2000)*(#1>2000)}
}

2000 以上的 x 单位距离减半。要获得正确的刻度标签,您还需要定义逆变换:

x coord inv trafo/.code={
    \pgfmathparse{#1+(#1-2000)*(#1>2000)}
}

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\usepgfplotslibrary{groupplots}

\begin{document}

\begin{tikzpicture}
\begin{groupplot}[
    group style={
        group name=my plots,
        group size=1 by 2,
        xlabels at=edge bottom,
        xticklabels at=edge bottom,
        vertical sep=0pt
    },
    width=16cm,
    height=6cm,
    xmin=500, xmax=4000,
    x dir= reverse,
    ymin=40,ymax=105,
    tickpos=left,
    x coord trafo/.code={
        \pgfmathparse{#1-0.5*(#1-2000)*(#1>2000)}
    },
    x coord inv trafo/.code={
        \pgfmathparse{#1+(#1-2000)*(#1>2000)}
    },
    xtick={500,1000,1500,2000,3000,4000},
    enlargelimits=false,
    ytick align=outside,
    xtick align=outside,
    domain=500:4000, samples=100
]

\nextgroupplot
\pgfmathsetseed{1}
\addplot [smooth] {(x<2000)*rnd*50+40+rnd*5};
\nextgroupplot
\addplot [smooth] {(x<2000)*rnd*50+40+rnd*5};
\end{groupplot}

\end{tikzpicture}
\end{document}

相关内容