Tikzpicture - 如何使主要刻度線更長或更粗

Tikzpicture - 如何使主要刻度線更長或更粗

我試圖使主要刻度(11、12、13、14、15、16、17、18、19 和 20)更粗或更長,以便更容易看到箱線圖統計數據。有誰知道如何實現這一目標?

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{xcolor}
\usetikzlibrary{arrows}
\usepgfplotslibrary{fillbetween}
\usepgfplotslibrary{statistics}
\usetikzlibrary{shapes.misc}
\begin{document}
\begin{tikzpicture}
\pgfmathsetlengthmacro\MajorTickLength{
    \pgfkeysvalueof{/pgfplots/major tick length} * 4
}
\begin{axis}
[
ytick=\empty,
xmin=11,
xmax=20,
xmajorticks=true,
minor x tick num=4,
xtick={11,12,13,14,15,16,17,18,19,20},
axis x line=bottom,
axis line style={latex-latex},
axis y line=none,
enlargelimits=0.05,
height=3.5cm,
width=13cm,
clip=false
]

\addplot[
yshift=0.1cm,
boxplot prepared={
median=15.5,
upper quartile=17.6,
lower whisker=11,
lower quartile=13.6,
upper whisker=19,
whisker extend=0 % height of whiskers
},black
] coordinates {};
%
\end{axis}
\end{tikzpicture}
\end{document}

謝謝你!

電流輸出

答案1

在第 342 頁上手動的(版本 1.16),它引入了自訂選項every minor tick/.append style={...}every major tick/.append style={...}你需要使用minor tick length = somethingandmajor tick length= something裡面。我已將您的程式碼壓縮為一個最小的範例。

PS你不需要\pgfmathsetlengthmacro\MajorTickLength{...}

輸出

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat = newest} % Current version is 1.16

\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
ytick=\empty,
xmin=11,
xmax=20,
minor x tick num=4,
xtick={11,12,13,14,15,16,17,18,19,20},
%%%%%%%%%%%%%%%%%%%% What you need:
every major tick/.append style={very thick, major tick length=10pt, black},
every minor tick/.append style={thick, minor tick length=3pt, red},
%%%%%%%%%%%%%%%%%%%%
axis x line=bottom,
axis line style={latex-latex},
axis y line=none,
enlargelimits=0.05,
height=3.5cm,
width=13cm,
clip=false,
]
\addplot[
yshift=0.2cm,
boxplot prepared={
median=15.5,
upper quartile=17.6,
lower whisker=11,
lower quartile=13.6,
upper whisker=19,
whisker extend=0 % height of whiskers
},black
] coordinates {};
%
\end{axis}
\end{tikzpicture}
\end{document}

答案2

\pgfmathsetlengthmacro\MajorTickLength{...}剛剛創建了一個長度並為其存儲了一些值,但您從未應用該值在某處。因此,透過添加major tick length=\MajorTickLengthaxis您將得到您想要的結果。

請注意,我極大地簡化了您的程式碼——正如 M. Al Jumaily 在他的回答以及——達到同樣的結果......

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
    \pgfmathsetlengthmacro\MajorTickLength{
        \pgfkeysvalueof{/pgfplots/major tick length} * 4
    }
    \begin{axis}[
        height=4cm,             % <-- (adjusted)
        width=13cm,
        axis x line=bottom,
        axis y line=none,
        axis line style={latex-latex},
        xmin=11,
        xmax=20,
        xtick distance=1,       % <-- (added)
        minor x tick num=4,
        ytick=\empty,
        major tick length=\MajorTickLength, % <-- added
        enlarge x limits=0.05,  % <-- (changed)
        enlarge y limits=0.25,  % <-- (added and adjusted)
    ]

        \addplot[
            boxplot prepared={
                median=15.5,
                upper quartile=17.6,
                lower whisker=11,
                lower quartile=13.6,
                upper whisker=19,
                whisker extend=0, % height of whiskers
            },
            black,
        ] coordinates {};

    \end{axis}
\end{tikzpicture}
\end{document}

顯示上述程式碼結果的圖像

相關內容