![水平刻度与条形图不准确对应](https://linux22.com/image/468312/%E6%B0%B4%E5%B9%B3%E5%88%BB%E5%BA%A6%E4%B8%8E%E6%9D%A1%E5%BD%A2%E5%9B%BE%E4%B8%8D%E5%87%86%E7%A1%AE%E5%AF%B9%E5%BA%94.png)
这是我的代码:
\documentclass[12pt,a4paper,onecolumn, openright]{report}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
% Define bar chart colors
%
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}
\begin{document}
\begin{tikzpicture}
\useasboundingbox (20em,20em) rectangle (5em,5em);
\begin{axis}[
width = 20cm,
height = 8cm,
% major x tick style = transparent,
ybar=0pt,
ymajorgrids = true,
ylabel = {Bleu},
% xtick = {fr2zh},
% xticklabels = {fr2zh, de2zh, it2zh, ja2zh, ko2zh, vi2zh, null1, zh2de, zh2it, zh2ja, zh2ko, zh2vi, zh2fr},
symbolic x coords={fr2zh, de2zh, it2zh, ja2zh, ko2zh, vi2zh, zh2de, zh2it, zh2ja, zh2ko, zh2vi, zh2fr, fr2de, fr2it, fr2ja, fr2ko, fr2vi, de2fr, de2it, de2ja, de2ko, de2vi, it2fr, it2de, it2ja, it2ko, it2vi, ja2fr, ja2de, ja2it, ja2ko, ja2vi, ko2fr, ko2de, ko2it, ko2ja, ko2vi, vi2fr, vi2de, vi2it, vi2ja, vi2ko},
xtick = {fr2zh, de2zh, it2zh, ja2zh, ko2zh, vi2zh,zh2de, zh2it, zh2ja, zh2ko, zh2vi, zh2fr, fr2de, fr2it, fr2ja, fr2ko, fr2vi, de2fr, de2it, de2ja, de2ko, de2vi, it2fr, it2de, it2ja, it2ko, it2vi, ja2fr, ja2de, ja2it, ja2ko, ja2vi, ko2fr, ko2de, ko2it, ko2ja, ko2vi, vi2fr, vi2de, vi2it, vi2ja, vi2ko},
% xtick = data,
bar width=0.6em,%<- changed
xticklabel style={
inner sep=0pt,
anchor=north east,
rotate=60,
font = \tiny,
},
scaled y ticks = false,
% enlarge x limits=0.2,
ymin=0,
% legend cell align=left,
legend style={
at={(1,1.05)},
anchor=south east,
legend columns=-1,
column sep=1ex,
}
]
\addplot[style={blue!20,fill=blue!20,mark=none}]
coordinates {(fr2zh, 32.3) (de2zh,17.5) (it2zh,29.5) (ja2zh,26.4) (ko2zh,26.8) (vi2zh,30.4)};
\addplot[style={red!20,fill=red!20,mark=none}]
coordinates {(zh2de,29.7) (zh2it,25.8) (zh2ja,23.7) (zh2ko,21.6) (zh2vi,32.3) (zh2fr,35.5) };
\addplot[style={ggreen,fill=ggreen,mark=none}]
coordinates {(fr2de,32.4)
(fr2it,28.3) (fr2ja,24.6) (fr2ko,21.5) (fr2vi,34.5) (de2fr,37.6) (de2it,27.7) (de2ja,24) (de2ko,21.6) (de2vi,33.8) (it2fr,35.6) (it2de,29.3) (it2ja,22.8) (it2ko,20.2) (it2vi,31.6) (ja2fr,29.7) (ja2de,24.3) (ja2it,22.2) (ja2ko,20.7) (ja2vi,27.6) (ko2fr,30) (ko2de,25.6) (ko2it,21.7) (ko2ja,22.7) (ko2vi,28.3) (vi2fr,34.2) (vi2de,28.5) (vi2it,24.5) (vi2ja,22.8) (vi2ko,21)};
% \addplot[style={ppurple,fill=ppurple,mark=none}]
% coordinates {(EgyptHD,0.74) (Hover,1.07) (Navi,1.23)};
\legend{source2zh,zh2target,source2target}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
像这样?
\documentclass[12pt,a4paper,onecolumn, openright]{report}
\usepackage[margin=25mm]{geometry} % <---
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
% Define bar chart colors
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = \linewidth,%20cm,
height = 8cm,
%
ybar=-0.6em, % <---
bar width=0.6em,
%
ymajorgrids = true,
ylabel = {Bleu},
symbolic x coords={fr2zh, de2zh, it2zh, ja2zh, ko2zh, vi2zh, zh2de, zh2it, zh2ja, zh2ko, zh2vi, zh2fr, fr2de, fr2it, fr2ja, fr2ko, fr2vi, de2fr, de2it, de2ja, de2ko, de2vi, it2fr, it2de, it2ja, it2ko, it2vi, ja2fr, ja2de, ja2it, ja2ko, ja2vi, ko2fr, ko2de, ko2it, ko2ja, ko2vi, vi2fr, vi2de, vi2it, vi2ja, vi2ko},
xtick = {fr2zh, de2zh, it2zh, ja2zh, ko2zh, vi2zh,zh2de, zh2it, zh2ja, zh2ko, zh2vi, zh2fr, fr2de, fr2it, fr2ja, fr2ko, fr2vi, de2fr, de2it, de2ja, de2ko, de2vi, it2fr, it2de, it2ja, it2ko, it2vi, ja2fr, ja2de, ja2it, ja2ko, ja2vi, ko2fr, ko2de, ko2it, ko2ja, ko2vi, vi2fr, vi2de, vi2it, vi2ja, vi2ko},
% xtick = data,
xticklabel style={
inner sep=0pt,
anchor=north east,
rotate=60,
font = \tiny,
},
%
enlarge x limits={abs=1em},
ymin=0,
% legend cell align=left,
legend style={
at={(1,1.05)},
anchor=south east,
legend columns=-1,
column sep=1ex,
}
]
\addplot[style={blue!20,fill=blue!20,mark=none}]
coordinates {(fr2zh, 32.3) (de2zh,17.5) (it2zh,29.5) (ja2zh,26.4) (ko2zh,26.8) (vi2zh,30.4)};
\addplot[style={red!20,fill=red!20,mark=none}]
coordinates {(zh2de,29.7) (zh2it,25.8) (zh2ja,23.7) (zh2ko,21.6) (zh2vi,32.3) (zh2fr,35.5) };
\addplot[style={ggreen,fill=ggreen,mark=none}]
coordinates {(fr2de,32.4)
(fr2it,28.3) (fr2ja,24.6) (fr2ko,21.5) (fr2vi,34.5) (de2fr,37.6) (de2it,27.7) (de2ja,24) (de2ko,21.6) (de2vi,33.8) (it2fr,35.6) (it2de,29.3) (it2ja,22.8) (it2ko,20.2) (it2vi,31.6) (ja2fr,29.7) (ja2de,24.3) (ja2it,22.2) (ja2ko,20.7) (ja2vi,27.6) (ko2fr,30) (ko2de,25.6) (ko2it,21.7) (ko2ja,22.7) (ko2vi,28.3) (vi2fr,34.2) (vi2de,28.5) (vi2it,24.5) (vi2ja,22.8) (vi2ko,21)};
\legend{source2zh,zh2target,source2target}
\end{axis}
\end{tikzpicture}
\end{document}
与您的相比,我的 MWE 中的主要变化在代码中以 标记<---
。