我编写了下面的乳胶命令来生成屏幕截图中显示的条形图。
接下来我想做的是将条形图的每个突出显示的尖端涂上更深的颜色,如图所示。这也可以通过使用 addplot + 坐标来实现吗?
\documentclass[]{article}
\usepackage[margin=0.05in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyhdr}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{color,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{polynom}
\usepackage{wallpaper}
\usepackage{lscape}
\usepackage{pgf-pie}
\usetikzlibrary{shapes.geometric}
\usepgfplotslibrary{fillbetween}
\usepgfplotslibrary{statistics}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\pgfplotsset{ every non boxed x axis/.append style={x axis line style=-},
every non boxed y axis/.append style={y axis line style=-}}
%
\text{}\\
\\
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis line style={thick,-},
name=like,
%
scale only axis,
xbar,
%
%
xmin=0,
xmax=100,
ymin=0.1,
ymax=1.3,
%
grid style={line width=.1pt, draw=black!60},
grid=major,
ymajorgrids=true,
%
tick label style={font=\Large},
width=6.2cm,
height=3.0cm,
%
xtick={20,40,60,80,100},
ytick={0.3,0.6,0.9,1.2},
y tick label style={text width=2cm,align=center},
%
axis x line=left,
axis y line=none,
clip=false
]
\addplot[fill=red!20] coordinates {
(42,0.35)
(60,0.7)
(49,1.05)
};
%
%
\node[right] at (axis cs:42,0.35){\Large 42};
\node[right] at (axis cs:60,0.7){\Large 60};
\node[right] at (axis cs:49,1.05){\Large 49};
%
\node[xshift=-1.0cm,align=center] at (axis cs:0,1.05) {\Large Ghana};
\node[xshift=-1.0cm,align=center] at (axis cs:0,0.7) {\Large Mali};
\node[xshift=-1.0cm,align=center] at (axis cs:0,0.35) {\Large India};
%
\draw[line width=.1pt, draw=black!60] (axis cs:0,1.3) -- (axis cs:100,1.3);
\draw[line width=.1pt, draw=black!60] (axis cs:0,0) -- (axis cs:0,1.3);
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
先感谢您
答案1
试试这个(你的其他包都是不需要的):
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis line style={thick,-},
name=like,
%
scale only axis,
xbar stacked,
%
%
xmin=0,
xmax=100,
ymin=0.1,
ymax=1.3,
%
grid style={line width=.1pt, draw=black!60},
grid=major,
ymajorgrids=true,
%
tick label style={font=\Large},
width=6.2cm,
height=3.0cm,
%
xtick={20,40,60,80,100},
ytick={0.3,0.6,0.9,1.2},
y tick label style={text width=2cm,align=center},
%
axis x line=left,
axis y line=none,
clip=false
]
\addplot[fill=red!20] coordinates {
(40,0.35)
(40,0.7)
(40,1.05)
};
\addplot[fill=blue] coordinates {(2,0.35) (20,.7) (9,1.05)};
%
%
\node[right] at (axis cs:42,0.35){\Large 42};
\node[right] at (axis cs:60,0.7){\Large 60};
\node[right] at (axis cs:49,1.05){\Large 49};
%
\node[xshift=-1.0cm,align=center] at (axis cs:0,1.05) {\Large Ghana};
\node[xshift=-1.0cm,align=center] at (axis cs:0,0.7) {\Large Mali};
\node[xshift=-1.0cm,align=center] at (axis cs:0,0.35) {\Large India};
%
\draw[line width=.1pt, draw=black!60] (axis cs:0,1.3) -- (axis cs:100,1.3);
\draw[line width=.1pt, draw=black!60] (axis cs:0,0) -- (axis cs:0,1.3);
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
输出: