TeX - LaTeX Asked by Colin R on December 13, 2020
In the following code for a pgfplots bar chart, I use explicit xticklabels because I want simple integer labels, not exponentials or not-quite-right integers derived from them. But that means I also need to specify or adjust the placement of the xtick labels. Using xshift almost solves the problem, but somehow it loses the first tick label — which should be a 10 under the first group of 3 bars. What’s a good fix for this problem?
documentclass[a4paper]{article}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}
begin{semilogxaxis}[
log basis x=4,
width=10cm,
xlabel=size of input expressions,
xticklabels={10,40,160,640,2560},
x tick label style={xshift=2.5cm},
xmin=5, xmax=5120,
ylabel=geo. mean (output-size / input-size),
yticklabel=pgfmathprintnumber{tick}%,
enlargelimits=0.05,
ybar,
]
addplot
coordinates {(10,75.16) (40,76.38)
(160,76.91) (640,77.35) (2560,77.41)};
addplot
coordinates {(10,65.35) (40,59.68)
(160,56.85) (640,57.50) (2560,57.01)};
addplot
coordinates {(10,52.48) (40,23.40)
(160,6.09) (640,1.64) (2560,0.37)};
legend{std.,fuse,lift}
end{semilogxaxis}
end{tikzpicture}
end{document}
You really just need to specify the x-values where you want the ticks. Seeings as all five groups are represented in the first addplot
, you can simply add xtick=data
to the axis
options, and remove the xshift
for the labels.
If you want to remove the ticks you can do x tick style={/pgfplots/tickwidth=0}
.
documentclass[a4paper]{article}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}
begin{semilogxaxis}[
log basis x=4,
width=10cm,
xlabel=size of input expressions,
xticklabels={10,40,160,640,2560},
xmin=5, xmax=5120,
ylabel=geo. mean (output-size / input-size),
yticklabel=pgfmathprintnumber{tick}%,
enlargelimits=0.05,
ybar,
xtick=data,
x tick style={/pgfplots/tickwidth=0}
]
addplot
coordinates {(10,75.16) (40,76.38)
(160,76.91) (640,77.35) (2560,77.41)};
addplot
coordinates {(10,65.35) (40,59.68)
(160,56.85) (640,57.50) (2560,57.01)};
addplot
coordinates {(10,52.48) (40,23.40)
(160,6.09) (640,1.64) (2560,0.37)};
legend{std.,fuse,lift}
end{semilogxaxis}
end{tikzpicture}
end{document}
Correct answer by Torbjørn T. on December 13, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP