我的長條圖有一些比其他長條大的條形,如下所示:
我的問題是我看不到小條(例如,點 2 或點 4)。我們可以改變一些參數來縮放 y 軸嗎?
我的程式碼如下:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}[ht!]
\centering
\resizebox{.65\textwidth}{!}{%
\begin{tikzpicture}
\begin{axis}[
xlabel={Number},
ylabel={Percentage},
set layers,
ybar=1.2pt,
bar width=6pt,
symbolic x coords={2,4,6,8,10},
grid=both,
ymin=0,
samples=5,
legend cell align=left,
ymax=1,
x label style={font=\footnotesize},
y label style={font=\footnotesize},
ticklabel style={font=\footnotesize},
legend style={at={(0,.82)},anchor=west,font=\scriptsize},
]
%%
\addplot[black,fill=red,postaction={pattern=north east lines}] coordinates {
(2, 0.005) (4, 0.001) (6, 0.2) (8, 0.2) (10, 0.4)
};
\addlegendentry{A}
%%
\addplot[black,fill=brown,postaction={pattern=north west lines}] coordinates {
(2, 0.002) (4, 0.004) (6, 0.2) (8, 0.5) (10, 0.8)
};
\addlegendentry{B}
%%
\addplot[black,fill=violet,postaction={pattern=crosshatch}] coordinates {
(2, 0.2) (4, 0.007) (6, 0.4) (8, 0.7) (10, 0.9)
};
\addlegendentry{C}
\end{axis}
\end{tikzpicture}
}
\caption{The percentage.}
\label{figure:1}
\end{figure}
\end{document}
答案1
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}[ht!]
\centering
\resizebox{.65\textwidth}{!}{%
\begin{tikzpicture}
\begin{semilogyaxis}[
xlabel={Number},
ylabel={Percentage},
set layers,
ybar=1.2pt,
bar width=6pt,
symbolic x coords={2,4,6,8,10},
grid=both,
samples=5,
legend cell align=left,
ymax=1,
x label style={font=\footnotesize},
y label style={font=\footnotesize},
ticklabel style={font=\footnotesize},
legend style={at={(0,.82)},anchor=west,font=\scriptsize},
log origin y=infty
]
%%
\addplot[black,fill=red,postaction={pattern=north east lines}] coordinates {
(2, 0.005) (4, 0.001) (6, 0.2) (8, 0.2) (10, 0.4)
};
\addlegendentry{A}
%%
\addplot[black,fill=brown,postaction={pattern=north west lines}] coordinates {
(2, 0.002) (4, 0.004) (6, 0.2) (8, 0.5) (10, 0.8)
};
\addlegendentry{B}
%%
\addplot[black,fill=violet,postaction={pattern=crosshatch}] coordinates {
(2, 0.2) (4, 0.007) (6, 0.4) (8, 0.7) (10, 0.9)
};
\addlegendentry{C}
\end{semilogyaxis}
\end{tikzpicture}
}
\caption{The percentage.}
\label{figure:1}
\end{figure}
\end{document}