X軸を反転したX、Yチャートを描く

X軸を反転したX、Yチャートを描く

次のデータセットがあります:

X= 130, 65, 45, 22, 14, 10
Y= 1.8, 1.5, 1.2, 1.1, 0.9, 0.8

まず、私が書いたコードは非常に奇妙に見えます:

\begin{tikzpicture}
    \begin{axis}[
        title={My Chart},
        xlabel={X axis},
        ylabel={Y axis},
        ymin=0, ymax=2,
        xmin=0, xmax=140,
        ytick={1.8,1.5,1.2,1.1,0.9,0.8},
        xtick={10,14,22,45,65,130},
        legend pos=north west,
        ymajorgrids=true,
        grid style=dashed,
    ]

        \addplot[
            color=blue,
            mark=square,
        ]
        coordinates {
            (0,0)(1,1)(2,4)(3,9)(4,16)(5,25)(6,36)(7,49)(8,64)(9,81)(10,100)
        };
        \legend{Data 1}

    \end{axis}
\end{tikzpicture}

次のようにレンダリングされます:

ここに画像の説明を入力してください

下降トレンドを表示したいので、X 軸を反転させる必要があると思いますが、方法がわかりません。これが私が理想的に実現しようとしているチャートです。

ここに画像の説明を入力してください

答え1

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[x dir=reverse]
\addplot+ coordinates {(0,0)(1,1)(2,4)(3,9)(4,16)(5,25)(6,36)(7,49)(8,64)(9,81)(10,100)};
\end{axis}
\end{tikzpicture}
\end{document}

グラフが下向きに傾斜している

答え2

使用したドキュメント クラスを指定しなかったためです。standalone例として使用します。これは奇妙に見えます。実際のアプリケーションを知りたいと思います。ただし、これがその方法です。

実際には、オプションを使用するとより簡単な方法がありますx dir=reverse:

\documentclass[border=0.618cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    title={My Chart},
    xlabel={X axis},
    ylabel={Y axis},
    ymin=0.5, ymax=2,
    xmin=0, xmax=140,
    legend pos=north east,
    ymajorgrids=true,
    grid style=dashed,
    x dir=reverse
]
\addplot[
    color=blue,
    mark=square,
] coordinates {
    (130,1.8)(65,1.5)(45,1.2)(22,1.1)(14,0.9)(10,0.8)
};
\legend{Data 1}
\end{axis}
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報