我想
ylabel style={rotate=-90}
会阻止我的 y 轴旋转,但由于某种原因,这种情况仍然会发生。即使在我把
fill=white
下面是我的代码:
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{arrows}
\usepgfplotslibrary{statistics}
\usetikzlibrary{shapes.multipart,shapes.geometric,calc,angles,positioning,intersections,quotes,decorations,babel,patterns,fit}
\usetikzlibrary{decorations.markings}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
% !TeX spellcheck = en_GB
\tikzset{%
insert new path/.style={%
insert path={%
node[midway,sloped]{\tikz \draw[#1,thick] (-.2pt,0) -- ++(.2 pt,0);}
}
}
}
\thispagestyle{empty}
\setcounter{page}{1}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
%ticks=none,
xmin=-3,
xmax=70,
ymin=-3,
ymax=70,
xtick={0,5,10,15,20,25,30,35,40,45,50,55,60,65,70},
ytick={0,5,10,15,20,25,30,35,40,45,50,55,60,65,70},
height=11cm,
width=13cm,
axis line style={shorten >=-10pt, shorten <=-10pt},
ylabel style={
fill=white,
yshift=10pt,
rotate=-90
},
ylabel=Y LABEL,
xlabel style={
xshift=10pt,
fill=white
},
xlabel=X,
ylabel near ticks,
xlabel near ticks,
]
\node[below] at (axis cs:-1.5,0) {$O$};
\draw[fill=black](axis cs:50,45) circle (3pt);
\addplot[thick,color=black,samples=100,domain=0:70] {3*x+3.739};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
输出为
有人能指出我哪里做错了吗?
谢谢
答案1
我认为你需要区分ylabel style
和yticklabel style
。我还ylabel style={rotate=-90},
向下移动以使其工作。它必须在下面ylabel near ticks,
,否则旋转会被覆盖(或尚未定义)。
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{arrows}
\usepgfplotslibrary{statistics}
\usetikzlibrary{shapes.multipart,shapes.geometric,calc,angles,positioning,intersections,quotes,decorations,babel,patterns,fit}
\usetikzlibrary{decorations.markings}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
% !TeX spellcheck = en_GB
\tikzset{%
insert new path/.style={%
insert path={%
node[midway,sloped]{\tikz \draw[#1,thick] (-.2pt,0) -- ++(.2 pt,0);}
}
}
}
\thispagestyle{empty}
\setcounter{page}{1}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
%ticks=none,
xmin=-3,
xmax=70,
ymin=-3,
ymax=70,
xtick={0,5,10,15,20,25,30,35,40,45,50,55,60,65,70},
ytick={0,5,10,15,20,25,30,35,40,45,50,55,60,65,70},
height=11cm,
width=13cm,
axis line style={shorten >=-10pt, shorten <=-10pt},
yticklabel style={
fill=white,
%yshift=10pt,
},
ylabel=Y LABEL,
xticklabel style={
%xshift=10pt,
fill=white
},
xlabel=X,
ylabel near ticks,
xlabel near ticks,
ylabel style={rotate=-90},
]
\node[below] at (axis cs:-1.5,0) {$O$};
\draw[fill=black](axis cs:50,45) circle (3pt);
\addplot[thick,color=black,samples=100,domain=0:70] {3*x+3.739};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
答案2
根据@marmot 的回答,只是为了好玩(虽然很丑)一个小动画来查看选项的rotate
效果
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{arrows}
\usepgfplotslibrary{statistics}
\usetikzlibrary{shapes.multipart,shapes.geometric,calc,angles,positioning,intersections,quotes,decorations,babel,patterns,fit}
\usetikzlibrary{decorations.markings}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\usepackage{animate}
\begin{document}
% !TeX spellcheck = en_GB
\tikzset{%
insert new path/.style={%
insert path={%
node[midway,sloped]{\tikz \draw[#1,thick] (-.2pt,0) -- ++(.2 pt,0);}
}
}
}
\thispagestyle{empty}
\setcounter{page}{1}
\begin{center}
\begin{animateinline}[controls,loop]{3}
\multiframe{72}{ixb=0+15}{
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
%ticks=none,
xmin=-3,
xmax=70,
ymin=-3,
ymax=70,
xtick={0,5,10,15,20,25,30,35,40,45,50,55,60,65,70},
ytick={0,5,10,15,20,25,30,35,40,45,50,55,60,65,70},
height=11cm,
width=13cm,
axis line style={shorten >=-10pt, shorten <=-10pt},
yticklabel style={
fill=white,
%yshift=10pt,
rotate=\ixb
},
ylabel=Y LABEL,
xticklabel style={
%xshift=10pt,
fill=white,
rotate=\ixb
},
xlabel=X,
ylabel near ticks,
xlabel near ticks,
ylabel style={rotate=0},
]
\node[below] at (axis cs:-1.5,0) {$O$};
\draw[fill=black](axis cs:50,45) circle (3pt);
\addplot[thick,color=black,samples=100,domain=0:70] {3*x+3.739};
\end{axis}
\end{tikzpicture}
}
\end{animateinline}
\end{center}
\end{document}
答案3
稍微修改一下就好了土拨鼠的答案(代码中用 表示差异% <---
):
\documentclass[margin=3mm]{standalone}
%removed all not related definitions and packages
\usepackage{pgfplots}
\pgfplotsset{compat=1.16} % <---
\begin{document}
\begin{tikzpicture}
\begin{axis}[
height=11cm, width=13cm,
restrict y to domain=0:70, % <---
domain=0:70, % <---
samples=141, % <---
no marks, % <---
clip=false, % <---
% some fine-tuning for the display:
xmin=0, xmax=70,
ymin=0, ymax=70,
xtick={0,5,...,70}, % <---
ytick={0,5,...,70}, % <---
grid,
axis lines=center, % <---
axis line style={shorten >=-10pt, shorten <=-10pt},
ylabel=Y LABEL,
xlabel=X,
ylabel near ticks,
xlabel near ticks,
ylabel style={rotate=-90},
]
\addplot +[ultra thick] {3*x+3.739}; % <---
\node[below left] at (0,0) {$O$}; % <---
\fill (50,45) circle (3pt); % <---
\end{axis}
\end{tikzpicture}
\end{document}