![更改 pgfplots 中 x 变量的位置](https://linux22.com/image/464121/%E6%9B%B4%E6%94%B9%20pgfplots%20%E4%B8%AD%20x%20%E5%8F%98%E9%87%8F%E7%9A%84%E4%BD%8D%E7%BD%AE.png)
这是我的情节:
如您所见,x 变量彼此非常接近,并且表示具有误导性,因为变量“Gloria*”似乎有数据,但实际上所有带星号的变量都应该是空的。有没有办法在它们之间增加更多空间?也许可以将它们移近轴的交点?
这是我的情节代码:
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}
\definecolor{pinky}{HTML}{ff66ff}
\definecolor{greeny}{HTML}{99ffcc}
\definecolor{bluy}{HTML}{6699ff}
\definecolor{orangy}{HTML}{ffd966}
\definecolor{verdino}{HTML}{d9ff66}
\definecolor{rossino}{HTML}{ff6666}
\definecolor{celestino}{HTML}{66ffff}
\definecolor{arancino}{HTML}{ff8c66}
\definecolor{giallino}{HTML}{ffff66}
\definecolor{violetto}{HTML}{bf00ff}
\definecolor{rosino}{HTML}{ffcccc}
\definecolor{violazzo}{HTML}{eee6ff}
\definecolor{bluone}{HTML}{4400cc}
\definecolor{grigino}{HTML}{b3b3b3}
\definecolor{verdastro}{HTML}{009900}
\definecolor{verdillino}{HTML}{ccffcc}
\definecolor{nerino}{HTML}{003300}
\definecolor{gialligno}{HTML}{ffff00}
\definecolor{violello}{HTML}{ff0080}
\begin{tikzpicture}
\begin{axis}[
width = 0.85*\textwidth,
height = 8cm,
major x tick style = transparent,
ybar=2*\pgflinewidth,
bar width=4pt,
ymajorgrids = true,
ylabel = {Frequency},
symbolic x coords={Ed$\ast$,Amy$\ast$,Frank$\ast$,Gloria$\ast$,Gia,April},
xtick = data,
scaled y ticks = false,
enlarge x limits=0.25,
ymin=0,
legend cell align=left,
legend style={
at={(1,1.05)},
anchor=south east,
legend columns=7,
column sep=1ex
}
]
\addplot[style={bblue,fill=bblue,mark=none}]
coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,1)(April,21)}; %go
\addplot[style={rred,fill=rred,mark=none}]
coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,13)(April,19)}; %want
\addplot[style={ggreen,fill=ggreen,mark=none}]
coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,0)(April,2)}; %keep
\addplot[style={ppurple,fill=ppurple,mark=none}] coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,3)(April,18)}; %can
\addplot[style={pinky,fill=pinky,mark=none}] coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,0)(April,1)}; %be
\addplot[style={greeny,fill=greeny,mark=none}] coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,0)(April,1)}; %forget
\addplot[style={bluy,fill=bluy,mark=none}] coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,0)(April,2)}; %think
\addplot[style={orangy,fill=orangy,mark=none}]
coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,0)(April,1)}; %must
\addplot[style={verdino,fill=verdino,mark=none}]
coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,0)(April,1)}; %see
\addplot[style={rossino,fill=rossino,mark=none}]
coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,0)(April,5)}; %get
\addplot[style={celestino,fill=celestino,mark=none}]
coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,0)(April,1)}; %need
\addplot[style={arancino,fill=arancino,mark=none}]
coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,0)(April,1)}; %hafta
\addplot[style={violetto,fill=violetto,mark=none}]
coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,0)(April,1)}; %hear
\legend{go,want,keep,can,be,forget,think,must,see,get,need,hafta,hear}
\end{axis}
\end{tikzpicture}
提前谢谢您!
答案1
刻度之间的距离太小。尝试将其放大,例如按定义的x
大小:
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}
\definecolor{pinky}{HTML}{ff66ff}
\definecolor{greeny}{HTML}{99ffcc}
\definecolor{bluy}{HTML}{6699ff}
\definecolor{orangy}{HTML}{ffd966}
\definecolor{verdino}{HTML}{d9ff66}
\definecolor{rossino}{HTML}{ff6666}
\definecolor{celestino}{HTML}{66ffff}
\definecolor{arancino}{HTML}{ff8c66}
\definecolor{giallino}{HTML}{ffff66}
\definecolor{violetto}{HTML}{bf00ff}
\definecolor{rosino}{HTML}{ffcccc}
\definecolor{violazzo}{HTML}{eee6ff}
\definecolor{bluone}{HTML}{4400cc}
\definecolor{grigino}{HTML}{b3b3b3}
\definecolor{verdastro}{HTML}{009900}
\definecolor{verdillino}{HTML}{ccffcc}
\definecolor{nerino}{HTML}{003300}
\definecolor{gialligno}{HTML}{ffff00}
\definecolor{violello}{HTML}{ff0080}
\begin{tikzpicture}
\begin{axis}[
% width = 0.85*\textwidth,
% height = 8cm,
major x tick style = transparent,
x=24mm, % <-----
ybar=2*\pgflinewidth,
bar width=4pt,
ymajorgrids = true,
ylabel = {Frequency},
symbolic x coords={Ed$\ast$,Amy$\ast$,Frank$\ast$,Gloria$\ast$,Gia,April},
xtick = data,
% scaled y ticks = false,
enlarge x limits=0.1, % <--- changed
ymin=0,
legend cell align=left,
legend style={at={(1,1.05)},
anchor=south east,
legend columns=7,
column sep=1ex
}
]
\addplot[style={bblue,fill=bblue,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,1)(April,21)}; %go
\addplot[style={rred,fill=rred,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,13)(April,19)}; %want
\addplot[style={ggreen,fill=ggreen,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,2)(April,2)}; %keep
\addplot[style={ppurple,fill=ppurple,mark=none}]
coordinates {(Ed$\ast$,0)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,3)(April,18)}; %can
\addplot[style={pinky,fill=pinky,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,2)(April,1)}; %be
\addplot[style={greeny,fill=greeny,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,2)(April,1)}; %forget
\addplot[style={bluy,fill=bluy,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,2)(April,2)}; %think
\addplot[style={orangy,fill=orangy,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,2)(April,1)}; %must
\addplot[style={verdino,fill=verdino,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,2)(April,1)}; %see
\addplot[style={rossino,fill=rossino,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,2)(April,5)}; %get
\addplot[style={celestino,fill=celestino,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,2)(April,1)}; %need
\addplot[style={arancino,fill=arancino,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,2)(April,1)}; %hafta
\addplot[style={violetto,fill=violetto,mark=none}]
coordinates {(Ed$\ast$,1)(Amy$\ast$,0)(Frank$\ast$,0)(Gloria$\ast$,0)(Gia,2)(April,1)}; %hear
\legend{go,want,keep,can,be,forget,think,must,see,get,need,hafta,hear}
\end{axis}
\end{tikzpicture}
\end{document}
在上面的 MWE 中,一些 y 条值被改变,以便它们更加清晰可见。