更改 pgfplots 中误差线帽的宽度

更改 pgfplots 中误差线帽的宽度

我想使用以下命令增加图表中误差线的粗细。

\pgfplotsset{/pgfplots/error bars/error bar style={ultra thick,black}}

但是,正如您在图片中看到的,它不会改变误差线帽的宽度。在此处输入图片描述

有谁知道如何解决这一问题?

我曾经\newcommand{\myfont}{\fontfamily{cmss}\fontseries{ul}\selectfont}让文本字体变浅,但不知何故也没有效果。例如,看看 [J/m^2] 单位。有人可以对此发表评论吗?

这是我使用的完整代码

\documentclass[a4paper]{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}%fitting functions
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\pgfkeys{/pgf/number format/.cd,1000 sep={}}


\newcommand{\myfont}{\fontfamily{cmss}\fontseries{ul}\selectfont}% used with mathpazo 


\pgfplotsset{compat=1.15}
\pgfplotsset{label style={font=\Large},
            tick label style={font=\Large}}

\pgfplotsset{error bars/.cd,
    x dir=both, x explicit,
    y dir=both, y explicit,
    }
\pgfplotsset{/pgfplots/error bars/error bar style={ultra thick,black}}
%\pgfplotsset{/pgfplots/label shift={0pt}}


\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[scale=1]
\begin{axis}[
    enable tick line clipping=false, % makes all ticks same width
    width=9cm,
    height=7cm,
    axis line style=semithick,
    legend style={at={(0.95,0.3)},draw=none},
    legend cell align={right},
    x tick style={black,semithick},
    x label style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    xmin=0,xmax=20,
    xtick={0,5,10,...,20},
    xtick pos=bottom,
    xtick align=outside,
    y tick style={black,semithick},
    y label style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    ymin=0,ymax=1000,
    ytick={0,200,...,1000},
    ytick pos=left,
    ytick align=outside,
    xlabel={$h$ [$\mu${\myfont m}]},
    ylabel={$G_a$ [{\myfont J/m}$^2$]}
]
    \addplot [only marks,mark=*,mark options={scale=1.5,fill=black}]
         table [x=x, y=y, x error=ex, y error=ey] {
        x       ex      y       ey
        0       0       0       0
        1.9     0.24        190     8
        7       0.49        515     7
        15      0.73        812     5
    };

    \addplot [only marks,mark=o,mark options={scale=1.5,thick}] table [x=x, y=y, x error=ex, y error=ey] {
        x       ex      y       ey
        1.03    0.09        90      0
        2.2     0.18        180     0
        4.4     0.26        300     0
    };

\end{axis}
\end{tikzpicture}
\end{figure}


\end{document}

答案1

在这个答案中,我只提到了误差线的粗细,我对字体粗细没什么可说的。简短的回答是,将pgfplots绘图标记堆叠在末尾,并且这些标记的宽度不受您选择的线宽的影响。(较长的答案,我不会详细说明,会告诉您嵌套pgfplotss tikzpicture,这从手册 v1.16 第 318 页顶部的代码中可以看出。在我看来,这种嵌套的结果很难控制。)因此,您需要做的就是定义一个更粗的绘图标记

\pgfdeclareplotmark{fat-}
{%
  \pgfsetlinewidth{2pt}
  \pgfpathmoveto{\pgfqpoint{\pgfplotmarksize}{0pt}}%
  \pgfpathlineto{\pgfqpoint{-\pgfplotmarksize}{0pt}}%
  \pgfusepathqstroke
}%

宽度2pt可能应该降低,然后将其插入。

\documentclass[a4paper]{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}%fitting functions
\usepackage{tikz}
\usetikzlibrary{tikzmark,arrows.meta}

\pgfkeys{/pgf/number format/.cd,1000 sep={}}


\newcommand{\myfont}{\fontfamily{cmss}\fontseries{ul}\selectfont}% used with mathpazo 

\pgfdeclareplotmark{fat-}
{%
  \pgfsetlinewidth{2pt}
  \pgfpathmoveto{\pgfqpoint{\pgfplotmarksize}{0pt}}%
  \pgfpathlineto{\pgfqpoint{-\pgfplotmarksize}{0pt}}%
  \pgfusepathqstroke
}%


\pgfplotsset{compat=1.15}
\pgfplotsset{label style={font=\Large},
            tick label style={font=\Large}}

\pgfplotsset{error bars/.cd,
    x dir=both, x explicit,
    y dir=both, y explicit,
    }
\pgfplotsset{/pgfplots/error bars/error bar style={ultra thick,black},
/pgfplots/error bars/error mark={fat-}
}
%\pgfplotsset{/pgfplots/label shift={0pt}}


\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[scale=1]
\begin{axis}[
    enable tick line clipping=false, % makes all ticks same width
    width=9cm,
    height=7cm,
    axis line style=semithick,
    legend style={at={(0.95,0.3)},draw=none},
    legend cell align={right},
    x tick style={black,semithick},
    x label style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    xmin=0,xmax=20,
    xtick={0,5,10,...,20},
    xtick pos=bottom,
    xtick align=outside,
    y tick style={black,semithick},
    y label style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    ymin=0,ymax=1000,
    ytick={0,200,...,1000},
    ytick pos=left,
    ytick align=outside,
    xlabel={$h$ [$\mu${\myfont m}]},
    ylabel={$G_a$ [{\myfont J/m}$^2$]}
]
    \addplot [only marks,mark=*,mark options={scale=1.5,fill=black}]
         table [x=x, y=y, x error=ex, y error=ey] {
        x       ex      y       ey
        0       0       0       0
        1.9     0.24        190     8
        7       0.49        515     7
        15      0.73        812     5
    };

    \addplot [only marks,mark=o,mark options={scale=1.5,thick}] table [x=x, y=y, x error=ex, y error=ey] {
        x       ex      y       ey
        1.03    0.09        90      0
        2.2     0.18        180     0
        4.4     0.26        300     0
    };

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

在此处输入图片描述

相关内容