使用 pgfplots 针对特定域的拉伸函数

使用 pgfplots 针对特定域的拉伸函数

我有一张描绘 24 小时内值的图。>95% 的数据在域中y \in [1,10],所以我想将网格矩形大小减小一半。以下是我希望刻度在 10 之后变成什么样子的粗略示例 -exampleUno

我知道我可以转换坐标(你会看到它被注释掉了),但这并不能改变刻度距离,这会给人一种缩小网格的错觉,以查看图形中稀疏区域中的更多点,这样可以节省垂直空间。

翻阅文档pgfplots,我不确定这是否正常可行。我对其他软件包中的任何内容都持开放态度。

\documentclass[a4paper]{article}
\usepackage[top=0.5cm, bottom=0.8cm, left=1cm, right=1cm]{geometry}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{dateplot}
\pgfplotsset{
    width=18.5cm,
    height=9cm,%6.8cm
    compat=1.15,
    every axis/.append style={
        line width=1pt,
        tick style={line width=0.8pt}},
    colormap={cm}{color(0)=(blue!75) color(2.8)=(green) color(5.5)=(orange) color(16)=(red)},%
    }
\begin{document}
\begin{figure}[hb]\centering
    \begin{tikzpicture}
        \begin{axis}[
            tick align=outside,
            date coordinates in=x,
            table/col sep=comma,
            xticklabel={\hour},
            xlabel={Feb 2018},
            xmin=2018-02-01 23:45,
            xmax=2018-02-03 00:15,
            xtick distance= 0.04167,% 1/24, unit is hours
            % y coord trafo/.code={
            %   \pgfmathparse{#1-0.5*(#1-10)*(#1>10)}},
            % y coord inv trafo/.code={
            %    \pgfmathparse{#1+(#1-10)*(#1>10)}},
            ymin=1,%ymax=17.25,
            yticklabel={\pgfmathprintnumber{\tick}},
            ylabel={...},
            ytick distance=1,
            grid=both,
        ]
    \addplot [
        only marks, 
        scatter,
    ] table [x index=0,y index=1] {
    2018-02-02 11:18, 2.7
    2018-02-02 14:52, 3.7
    2018-02-02 18:05, 4.1
    2018-02-02 06:00, 6.8
    2018-02-02 13:32, 5.0
    2018-02-02 17:38, 2.4
    2018-02-02 22:49, 4.7
    2018-02-02 00:05, 2.7
    2018-02-02 03:02, 5.2
    2018-02-02 12:47, 8.5
    2018-02-02 16:00, 3.2
    2018-02-02 17:54, 5.8
    2018-02-02 19:47, 5.5
    2018-02-02 01:01, 5.5
    2018-02-02 14:49, 8.4
    2018-02-02 16:26, 6.1
    2018-02-02 18:17, 3.7
    2018-02-02 02:08, 4.9
    2018-02-02 04:52, 2.4
    2018-02-02 13:45, 4.4
    2018-02-02 17:06, 2
    2018-02-02 18:27, 5.0
    2018-02-02 01:55, 3.4
    2018-02-02 12:38, 4.7
    2018-02-02 15:08, 6.2
    2018-02-02 20:56, 6.2
    2018-02-02 06:04, 2.6
    2018-02-02 15:52, 3.2
    2018-02-02 17:57, 2.8
    2018-02-02 21:05, 2.8
    2018-02-02 22:20, 3.1
    2018-02-02 00:06, 3.3
    2018-02-02 01:18, 11.4
    2018-02-02 05:56, 2.2
    2018-02-02 13:38, 3.6
    2018-02-02 16:49, 2.2
    2018-02-02 21:02, 5.3
    2018-02-02 01:08, 2.2
    2018-02-02 13:46, 3.4
    2018-02-02 17:46, 4.0
    2018-02-02 22:28, 2.8
    2018-02-02 05:38, 12.4
    2018-02-02 14:35, 3.6
    2018-02-02 17:41, 3.2
    2018-02-02 03:17, 2.4
    2018-02-02 08:39, 5.7
    2018-02-02 12:36, 10.0
    2018-02-02 13:41, 6.2
    2018-02-02 20:15, 4.6
    2018-02-02 01:57, 6.3
    2018-02-02 03:35, 3.2
    2018-02-02 04:29, 2.9
    2018-02-02 13:06, 7.3
    2018-02-02 17:55, 3.4
    2018-02-02 21:43, 2.6
    2018-02-02 23:58, 4.2
    2018-02-02 04:28, 2.1
    2018-02-02 15:14, 11.7
    };
        \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}

答案1

也许现在我正确地猜出了你想要什么。

enter image description here

\documentclass[a4paper]{article}
\usepackage[top=0.5cm, bottom=0.8cm, left=1cm, right=1cm]{geometry}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepgfplotslibrary{dateplot}
\pgfplotsset{
    width=18.5cm,
    height=9cm,%6.8cm
    compat=1.15,
    every axis/.append style={
        line width=1pt,
        tick style={line width=0.8pt}},
    colormap={cm}{color(0)=(blue!75) color(2.8)=(green) color(5.5)=(orange) color(16)=(red)},%
    }
\begin{document}
\def\mya{0.75}
You are making a stretch transformation
\[ y~\mapsto~y'~=~y-a\,\Theta(y-10)\cdot (y-10)\]
in order to stretch the points above 10. $\Theta$ denotes the usual Heaviside
function. The inverse transformation is given by
\[ y(y')~=~y'+\frac{a}{1-a}\Theta(y'-10)\cdot (y'-10)\;.\]
If you want the stretching to be more pronounced, choose $a$ closer to 1. Here I
am going to take it to be $a=\mya$.
\begin{figure}[hb]\centering
    \begin{tikzpicture}
        \begin{axis}[
            tick align=outside,
            date coordinates in=x,
            table/col sep=comma,
            xticklabel={\hour},
            xlabel={Feb 2018},
            xmin=2018-02-01 23:45,
            xmax=2018-02-03 00:15,
            xtick distance= 0.04167,% 1/24, unit is hours
            y coord trafo/.code={
              \pgfmathparse{#1-\mya*(#1-10)*(#1>10)}},
            y coord inv trafo/.code={
               \pgfmathparse{#1+(\mya/(1-\mya))*(#1-10)*(#1>10)}},
            ymin=1,%ymax=17.25,
            extra y ticks={11,12,13},
            yticklabel={\pgfmathparse{int(\tick)}\ifnum\pgfmathresult=11
            \else
            \ifnum\pgfmathresult=13
            \else
            \pgfmathprintnumber{\tick}
            \fi
            \fi
            },
            %yticklabel={\pgfmathparse{int(ifthenelse(\tick<10.5,\tick,10+2*(\tick-10)))}\pgfmathresult},
            ylabel={...},
            ytick distance=1,
            grid=both,
        ]
    \addplot+[
        only marks, 
        scatter,
    ] table [x index=0,y index=1] {
    2018-02-02 11:18, 2.7
    2018-02-02 14:52, 3.7
    2018-02-02 18:05, 4.1
    2018-02-02 06:00, 6.8
    2018-02-02 13:32, 5.0
    2018-02-02 17:38, 2.4
    2018-02-02 22:49, 4.7
    2018-02-02 00:05, 2.7
    2018-02-02 03:02, 5.2
    2018-02-02 12:47, 8.5
    2018-02-02 16:00, 3.2
    2018-02-02 17:54, 5.8
    2018-02-02 19:47, 5.5
    2018-02-02 01:01, 5.5
    2018-02-02 14:49, 8.4
    2018-02-02 16:26, 6.1
    2018-02-02 18:17, 3.7
    2018-02-02 02:08, 4.9
    2018-02-02 04:52, 2.4
    2018-02-02 13:45, 4.4
    2018-02-02 17:06, 2
    2018-02-02 18:27, 5.0
    2018-02-02 01:55, 3.4
    2018-02-02 12:38, 4.7
    2018-02-02 15:08, 6.2
    2018-02-02 20:56, 6.2
    2018-02-02 06:04, 2.6
    2018-02-02 15:52, 3.2
    2018-02-02 17:57, 2.8
    2018-02-02 21:05, 2.8
    2018-02-02 22:20, 3.1
    2018-02-02 00:06, 3.3
    2018-02-02 01:18, 11.4
    2018-02-02 05:56, 2.2
    2018-02-02 13:38, 3.6
    2018-02-02 16:49, 2.2
    2018-02-02 21:02, 5.3
    2018-02-02 01:08, 2.2
    2018-02-02 13:46, 3.4
    2018-02-02 17:46, 4.0
    2018-02-02 22:28, 2.8
    2018-02-02 05:38, 12.4
    2018-02-02 14:35, 3.6
    2018-02-02 17:41, 3.2
    2018-02-02 03:17, 2.4
    2018-02-02 08:39, 5.7
    2018-02-02 12:36, 10.0
    2018-02-02 13:41, 6.2
    2018-02-02 20:15, 4.6
    2018-02-02 01:57, 6.3
    2018-02-02 03:35, 3.2
    2018-02-02 04:29, 2.9
    2018-02-02 13:06, 7.3
    2018-02-02 17:55, 3.4
    2018-02-02 21:43, 2.6
    2018-02-02 23:58, 4.2
    2018-02-02 04:28, 2.1
    2018-02-02 15:14, 11.7
    };
        \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}

相关内容