无论出于什么原因,在这个 pgfplot 中,垂直网格线与轴重叠(看起来很丑),尽管我在另一个网格线不重叠的图中使用了非常相似的轴。它看起来像这样:
最小工作示例:
\documentclass[a4paper,12pt]{report}
\usepackage{float}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgfplots, pgfplotstable}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\pgfplotsset{every tick label/.append style={font=\tiny}}
\pgfplotstableread[col sep=comma]{socket_ltncy_30s_recvmsg_8x1080p50_24g.csv}\datatable
\centering
\begin{axis}[
ybar,
ylabel near ticks,
axis line style = thin,
grid=major, grid style={gray!30},
bar width=.01cm,
width=\textwidth,
height=3cm,
xmin = 0,
xmax = 150,
ymin = 0,
ymax = 100,
xtick distance = {25},
ytick distance = {25},
yticklabel={\pgfmathprintnumber\tick\%},
xlabel={Latency in $\mu$s},
ylabel={ \textcolor{black}{Percent} },
label style={font=\scriptsize},
bar shift=0mm
],
\addplot[
draw=black,
fill=black,
bar shift=0mm
] table [
x={LATENCY},
y={PERCENT},
restrict expr to domain={y}{0.1:100}
]{\datatable};
\addplot[
scatter,
only marks,
mark=x,
color=black,
scatter/use mapped color={draw=black}
] table [
x={LATENCY},
y={PERCENT},
restrict expr to domain={y}{0.000001:0.1}
]{\datatable};
\addplot[
draw=green,
fill=green,
bar shift=0mm
] table [
x={LATENCY},
y={PERCENT},
restrict expr to domain={\thisrow{IS_MEDIAN}}{1:1}
]{\datatable};
\addplot[
draw=red,
fill=red,
bar shift=0mm
] table [
x={LATENCY},
y={PERCENT},
restrict expr to domain={\thisrow{IS_MEAN}}{1:1}
]{\datatable};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
数据socket_ltncy_30s_recvmsg_8x1080p50_24g.csv
看起来像这样
LATENCY,PERCENT,IS_MEDIAN,IS_MEAN
2,8.04666667,0,0
3,9.87416667,1,1
4,23.75833333,0,0
5,0.65000000,0,0
6,0.54166667,0,0
7,0.62416667,0,0
8,0.59750000,0,0
9,0.14500000,0,0
10,0.05166667,0,0
11,0.05583333,0,0
12,0.05166667,0,0
13,0.05333333,0,0
14,0.05666667,0,0
15,0.04833333,0,0
16,0.05583333,0,0
17,0.06166667,0,0
18,0.06083333,0,0
19,0.05666667,0,0
20,0.05833333,0,0
我希望它们向内“弯曲”,像这样:
谢谢你!
答案1
这不是网格线,而是刻度。添加tick align=inside
到axis
选项中,后选项ybar
。(ybar
似乎设置了xtick align=outside
,因此您需要覆盖该设置。)
不相关的旁注:pgfplots
加载tikz
,因此也pgf
加载 ,因此当您有 时,您无需明确加载后两者pgfplots
。我认为,环境\centering
中的tikzpicture
实际上不做任何事情,因此您可以将其删除。
最小示例:
\documentclass{report}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
%tick align=inside % uncomment this to see difference
]
\addplot {rnd};
\end{axis}
\end{tikzpicture}
\end{document}