在轴环境内添加额外的刻度

在轴环境内添加额外的刻度

我想知道是否可以在不声明选项的情况下向图中添加额外的刻度\begin{axis}。考虑以下示例,我希望计算点的坐标Ua出现在图表上。

\usepackage{tikz}
\usepackage[active,tightpage]{preview}  %generates a tightly fitting border around the work
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}
\usetikzlibrary{intersections}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
        xlabel={$u$},
        ylabel={$p$},
        restrict x to domain=0:1.5,
        ymin=-0.1, ymax=1.
        xtick={0},
        ytick={0.1,1}
        ]
        \addplot[name path global=RW,samples=50,domain=0:0.999999]
            ({sqrt(35)*(1-x^(1/7))},
            x);
        \addplot[name path global=SW,samples=50,domain=0.1:1]
            ({(x-0.1)/sqrt(7/400)/(1+sqrt(6/7*(10*x-1)))},
        x);
        \coordinate[circle,fill,inner sep=1pt, label=above right:{$U_1$}] 
            (U1) at (axis cs:0,1);
        \coordinate[circle,fill,inner sep=1pt, label=below right:{$U_2$}] 
            (U2) at (axis cs:0,0.1);
        \node[name intersections={of=RW and SW, by=Ua},circle,fill,inner sep=1pt] 
            at (Ua) {};
    \end{axis}
\end{document}

现在我也可以不用 来工作pgfplots,但由于我已经在文档中的其他图表中使用它了,因此一致性的实现会很麻烦。

答案1

这只是一个部分解决方案,也许不是最好的解决方案......它是部分的,因为绘制刻度的参数必须根据不同的图进行更改,并且因为只有主刻度(下方 x 轴和左侧 y 轴)

另请参阅此问题:交叉口坐标

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\usepackage{pgfplots}

\pgfplotsset{compat=newest}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}
\usetikzlibrary{intersections,calc}

\makeatletter

\newcommand\transformxdimension[1]{
    \pgfmathparse{((#1/\pgfplots@x@veclength)+
    \pgfplots@data@scale@trafo@SHIFT@x)/10^\pgfplots@data@scale@trafo@EXPONENT@x}
}

\newcommand\transformydimension[1]{
    \pgfmathparse{((#1/\pgfplots@y@veclength)+
    \pgfplots@data@scale@trafo@SHIFT@y)/10^\pgfplots@data@scale@trafo@EXPONENT@y}
}

\makeatother


\begin{document}

\begin{tikzpicture}

\begin{axis}[
    restrict x to domain=0:1.5,
    ymin=-0.1, ymax=1.,
    xmin=-0.1,xmax=1.6,
    clip=false,
    xtick={0},
    ytick={0.1,1}]

    \addplot[name path global=RW,samples=50,domain=0:0.999999]
        ({sqrt(35)*(1-x^(1/7))},x);
    \addplot[name path global=SW,samples=50,domain=0.1:1]
        ({(x-0.1)/sqrt(7/400)/(1+sqrt(6/7*(10*x-1)))},x);
    \coordinate[circle,fill,inner sep=1pt, label=above right:{$U_1$}] 
        (U1) at (axis cs:0,1);
    \coordinate[circle,fill,inner sep=1pt, label=below right:{$U_2$}] 
        (U2) at (axis cs:0,0.1);

    \draw[name intersections={of=RW and SW, name=i}] (i-1) -- (i-1)
    % this is only to have the coordinate of the intersection as last used coordinate

    \pgfextra{\pgfgetlastxy{\macrox}{\macroy}%
        \global\let\macrox\macrox%
        \global\let\macroy\macroy};
    %this save the x and y coordinate into \macrox and \macroy

    \node[circle,fill,inner sep=1pt] at (\macrox,\macroy) {};
    % draes the node at the intersection

    \draw[] (\macrox,0) -- (\macrox,3) node[pos=-1.5]
        {\transformxdimension{\macrox}
        \pgfmathprintnumber{\pgfmathresult}};
    \draw[] (0,\macroy) -- (3,\macroy) node[pos=-3.5]
        {\transformydimension{\macroy}
        \pgfmathprintnumber{\pgfmathresult}};
    % draws the x tick and y tick of the intersection

\end{axis}

\end{tikzpicture}

\end{document}

相关内容