我想更改每个刻度的样式(例如颜色、字体、刻度标记的大小和形状)。
在这个例子中,我想将数字(2,3,4)的颜色改为不同的颜色,并为每个数字定义一个特定的刻度标记。
\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.5}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
x=1.5cm,y=1cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-4,
xmax=4,
ymin=-4,
ymax=4,
xtick={-9,-8,...,9},
ytick={-5,-4,...,6},]
\clip(-5,-5) rectangle (5,5);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.5}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
x=1.5cm,y=1cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-4,
xmax=4,
ymin=-4,
ymax=4,
xtick={-9,-8,...,9},
ytick={-5,-4,...,6},
extra x ticks={4,3,2,1},
extra x tick labels={4,3,2,1},
extra x tick style={
xticklabel style={yshift=0.5ex, anchor=south, color=red, font=X}}]
\clip(-5,-5) rectangle (5,5);
\end{axis}
\end{tikzpicture}
\end{document}
第二个例子
\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.5}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
x=1.5cm,y=1cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-4,
xmax=4,
ymin=-4,
ymax=4,
xtick={-9,-8,...,9},
ytick={-5,-4,...,6},
extra x ticks={4,2},
extra x tick labels={$2\pi$, $4\pi$},
extra x tick style={
xticklabel style={yshift=0.5ex, anchor=south}}]
\clip(-5,-5) rectangle (5,5);
\end{axis}
\end{tikzpicture}
\end{document}