
다음 데이터 세트가 있습니다.
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
답변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}