y 次要网格没有显示。为什么?

y 次要网格没有显示。为什么?

你能告诉我为什么这张图上没有显示小网格线吗?这是因为我将 ymin 值设置为大于 0 吗?目前设置为 60。

感谢您的帮助!

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyhdr}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{color,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{polynom}
\usepackage{wallpaper}
\usepackage{flexisym}
\usepackage{caption}
\usepackage{varwidth}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis line style=thick,
axis lines=middle,
grid=major,
%
xminorgrids,
yminorgrids,
%
minor x tick num=4,
minor y tick num=4,
%
xmin=0,
xmax=7.2,
ymin=60,
ymax=101,
%
major grid style={line width=.2pt,draw=black!70},
%
height=11cm,
width=11cm,
%
%
tick label style={font=\large},
%
%
xlabel={\large Brand of remover},
ylabel={\large Concentration of acetone (\%)},
%
%
xtick={0,1,2,3,4,5,6,7},
xticklabels={{},{Brand A},{Brand B},{Brand C},{Brand D},{Brand E}},
ytick={0,60,65,70,75,80,85,90,95,100},
%
xticklabel style = {xshift=+0.4cm},
%
clip=false,
%every tick label/.append style={font=\tiny},
ylabel style={
anchor=south,
at={(ticklabel* cs:1.0)},
yshift=1pt
},
xlabel style={
anchor=west,
at={(ticklabel* cs:1.0)},
xshift=1pt
},
xticklabel style={
rotate=-315
}
]
%\node[above] at (axis cs:1.0,1.04) {\Large \bf Graph of the Concentration of Acetone Per Brand};
%
\node[left] at (axis cs:0,60) {\large 60};
%%
\draw[thick,fill=gray!60](axis cs:1,60) rectangle (axis cs:2,96);
\draw[thick,fill=gray!60](axis cs:2,60) rectangle (axis cs:3,76);
\draw[thick,fill=gray!60](axis cs:3,60) rectangle (axis cs:4,85);
\draw[thick,fill=gray!60](axis cs:4,60) rectangle (axis cs:5,62);
\draw[thick,fill=gray!60](axis cs:5,60) rectangle (axis cs:6,70);
\end{axis}
\end{tikzpicture}
\newpage
\end{document}

当前图像

答案1

您应该从列表中删除零ytick,因为您的图无论如何都是从 y = 60 开始的。在这种情况下,您甚至可以ytick完全省略该选项。

我不能完全确定它是否真的是这样的,但我强烈猜测它是这样的:PGF 可能采用列表中前两个值的距离ytick来计算 y 轴的次要网格刻度。您定义ytick={0,60,65,70,75,80,85,90,95,100}minor y tick num=4,因此 PGF 将 60 除以 4 并将次要 y 刻度的距离设置为 15。但是,这大于列表中以下值之间的距离ytick,因此您在 y 轴上看不到任何网格线。

如果删除零(或整个ytick列表),PGF 将正确设置次要 y 刻度的距离为 (65 - 60) / 4 = 1.25。

我从您的代码中删除了本示例不需要的包。我建议您清理代码,因为您多次加载了多个包,还加载了其他包已经加载的包或用于替换您加载的旧包的包。

我还建议您使用axis x line = bottom, axis y line = left而不是axis lines=middle,因为这会自动在 y = 60 处添加刻度。

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis line style=thick,
%axis lines=middle,
axis x line = bottom,
axis y line = left,
grid=major,
%
xminorgrids,
yminorgrids,
%
minor x tick num=4,
minor y tick num=4,
%
xmin=0,
xmax=7.2,
ymin=60,
ymax=101,
%
major grid style={line width=.2pt,draw=black!70},
%
height=11cm,
width=11cm,
%
%
tick label style={font=\large},
%
%
xlabel={\large Brand of remover},
ylabel={\large Concentration of acetone (\%)},
%
%
xtick={0,1,2,3,4,5,6,7},
xticklabels={{},{Brand A},{Brand B},{Brand C},{Brand D},{Brand E}},
%ytick={0,60,65,70,75,80,85,90,95,100},                                     % <-- !
%
xticklabel style={xshift=+0.4cm},
%
clip=false,
%every tick label/.append style={font=\tiny},
ylabel style={
rotate=-90,
anchor=south,
at={(ticklabel* cs:1.0)},
yshift=1pt
},
xlabel style={
anchor=west,
at={(ticklabel* cs:1.0)},
xshift=1pt
},
xticklabel style={
rotate=-315
}
]
%\node[above] at (axis cs:1.0,1.04) {\Large \bf Graph of the Concentration of Acetone Per Brand};
%
%\node[left] at (axis cs:0,60) {\large 60};
%%
\draw[thick,fill=gray!60](axis cs:1,60) rectangle (axis cs:2,96);
\draw[thick,fill=gray!60](axis cs:2,60) rectangle (axis cs:3,76);
\draw[thick,fill=gray!60](axis cs:3,60) rectangle (axis cs:4,85);
\draw[thick,fill=gray!60](axis cs:4,60) rectangle (axis cs:5,62);
\draw[thick,fill=gray!60](axis cs:5,60) rectangle (axis cs:6,70);
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容