单独的条形颜色

单独的条形颜色

我正在尝试创建一个条形图,其中除一个条形外,所有条形都是蓝色的,但最后一个条形没有标签。以下是我的 LaTeX 代码,任何帮助都将不胜感激。

https://www.overleaf.com/read/xczfctmnngvs

答案1

如果您仔细观察,就会发现在您的版本中,蓝色条形图也位于刻度线的左侧,而橙色条形图则位于刻度线的右侧(如果有刻度线)。因此,您需要将条形图移位,使它们位于刻度线上方。这可以通过引入绝对移位来实现0mm。(要查看这是否真的有用,只需注释掉这些指令并比较结果。)然后,您可以添加一个假蓝色条形图,并在其上方放置一个橙色条形图。

\documentclass[12pt]{article}
\usepackage{fancyhdr}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand*{\ttdefault}{\familydefault}
\usepackage[paperwidth=29.7cm,paperheight=42cm,left =1cm, top = 1cm, right =1cm, bottom = 1cm ,marginparwidth=0cm]{geometry}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\usepackage[table,xcdraw]{xcolor}
\usepackage[document]{ragged2e}
\usepackage[export]{adjustbox}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{float}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{caption}
\usepackage{calc}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{lastpage}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage{filecontents}
\usepackage{textcomp}
\usepackage{changepage}
\usepackage{times}
\captionsetup[table]{labelformat=empty}
\captionsetup{justification=raggedright,singlelinecheck=false}
\pgfplotsset{width=10cm,compat=newest}
\usetikzlibrary{plotmarks}
\usepgfplotslibrary{dateplot}
\tikzset{every picture/.append style={font=\normalsize}} % size graph font
\graphicspath{{/aspfiles/latexReportImages/}}
\usetikzlibrary{arrows, positioning, calc}
\newcolumntype{Y}{>{\centering\arraybackslash}X} %
\def\tabularxcolumn#1{m{#1}}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\pagestyle{fancy}
\definecolor{color1}{HTML}{181F50}
\definecolor{imagine}{HTML}{87cfeb}
\definecolor{lightblue}{HTML}{4f81c5}
\definecolor{oxfordblue}{HTML}{1f3057}
\definecolor{seagreen}{HTML}{96bf65}
\definecolor{olivegreen}{HTML}{4b5729}
\definecolor{lightbeige}{HTML}{f5e7a1}
\definecolor{goldenyellow}{HTML}{fcc808}
\definecolor{champagne}{HTML}{e6c18d}
\definecolor{salmonpink}{HTML}{f3b28b}
\definecolor{ruby}{HTML}{982d57}
\definecolor{lightorange}{HTML}{ffc299}
\definecolor{lightgray}{HTML}{bec0b8}
\definecolor{lightviolet}{HTML}{c9a8ce}
\definecolor{shellpink}{HTML}{fbded6}
\definecolor{mediumblue}{HTML}{0000CD}
\definecolor{lilac}{HTML}{c9a8ce}
\definecolor{saxo}{HTML}{1C5B92}
\definecolor{blue2}{HTML}{99c2ff}
\definecolor{lightgray2}{HTML}{d1d1e0}
\definecolor{redpink}{HTML}{ff9999}
\definecolor{lightyellow}{HTML}{ffffb3}
\definecolor{lightgreen}{HTML}{b3ffb3}
\definecolor{customcolor}{HTML}{00cc00}
\makeatletter
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\tikzstyle{chart}=[
legend label/.style={font={\Large},anchor=west,align=left},
legend box/.style={rectangle, draw, minimum size=10pt},
axis/.style={black,semithick,->},
axis label/.style={anchor=east,font={\tiny}}]
\newcommand{\pie}[5][]{
\begin{scope}[#1]
\pgfmathsetmacro{\curA}{90}
\pgfmathsetmacro{\r}{#2}
\def\c{(0,0)}
\node[pie title] at (270:\r + 0.5) {#3};
\foreach \v/\s/\l/\x in{#4}{
\pgfmathsetmacro{\deltaA}{\v/100*360}
\pgfmathsetmacro{\nextA}{\curA + \deltaA}
\pgfmathsetmacro{\midA}{(\curA+\nextA)/2}
\path[slice,\s] \c
-- +(\curA:\r)
arc (\curA:\nextA:\r)
-- cycle;
\begin{pgfonlayer}{foreground}
\path \c -- node[pos=\x,pie values,values of \s,font={#5}]{\l} +(\midA:\r);
\end{pgfonlayer}
\global\let\curA\nextA
}
\end{scope}
}
\newcommand{\legend}[2][]{
\begin{scope}[#1]
\path
\foreach \n/\s in {#2}{++(0,-10pt) node[\s,legend box] {} +(5pt,0) node[legend label] {\n}};
\end{scope}
}
\begin{document}
\pgfplotscreateplotcyclelist{defaultCycle}{%
lightblue,ultra thick,sharp plot,mark=no\\%
orange,ultra thick,sharp plot,mark=no\\%
oxfordblue,ultra thick,sharp plot,mark=no\\%
lightgray2,ultra thick,sharp plot,mark=no\\%
lightorange,ultra thick,sharp plot,mark=no\\%
redpink,ultra thick,sharp plot,mark=no\\%
blue2,ultra thick,sharp plot,mark=no\\%
lightgreen,ultra thick,sharp plot,mark=no\\%
purple,ultra thick,sharp plot,mark=no\\%
olivegreen,ultra thick,sharp plot,mark=no\\%
champagne,ultra thick,sharp plot,mark=no\\%
lilac,ultra thick,sharp plot,mark=no\\%
lightyellow,ultra thick,sharp plot,mark=no\\%
}


\flushleft
    \begin{tikzpicture}
    \begin{axis}[
    cycle list name=defaultCycle,
    width=0.5\linewidth,
    height=0.2\textheight,
    symbolic x coords={a,b,c,d,e},
    xtick=data,
    yticklabel style={/pgf/number format/fixed, /pgf/number format/1000 sep},
    scaled y ticks=false,
    xtick pos=left,
            legend style={draw=none,at={(0,1.03)},anchor=south west},
    legend columns=-1,
    yticklabel style={rotate=0},,
    bar width=20pt,             % reduced bar width for overlapping,
    x tick label style ={font=\normalsize,text width=2cm,align=center,anchor=north},
    ymajorgrids,
    ybar,
    %xtickmin=a, xtickmax=e,
    ytick pos=left,
    xlabel=\textbf{},
    ylabel=\textbf{},
    title={\textbf{}}
    ]
        \addplot[ybar,fill=lightblue,mark=no,bar shift=0mm] coordinates {
         (a,3.5)
         (b,-0.75)
         (c,-4.85)
         (d,-3.33)
         (e,0)
        };
        \addplot[ybar,fill=orange,mark=no,bar shift=0mm] coordinates {
         (e,7)
        };
    \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容