# Tag Info

41

The pgfplots manual gives a lot of information and tutorials- you'll also find a lot of great examples on this site. Here's a humble tutorial on how I created the following bar graph, which I used in answering How to clarify and enliven a dense table using the wonderful pgfplots package; the complete code is given at the end. Reading the data The first ...

37

To decrease the space between the groups, you can increase the x axis range by using enlarge x limits=0.25 (which increases the axis range by 25% compared to the data range). To remove the spacing between the bars, use ybar=0pt instead of just ybar. Note that this will lead to slight overlaps between the bars due to their outlines. To avoid this, you could ...

34

You can set the spacing between the bars using the optional argument to ybar (the default is 2pt). For indicating that some of the data values exceed the axis range, you could clip the values at some level that's slightly larger than your axis limit using restrict y to domain*=0:<value>, making sure that you set clip=false so that the bars can ...

29

For bar charts you can use pgfplots With TikZ you can setup some macros so that you can write pie charts like this: \begin{tikzpicture} [ pie chart, slice type={comet}{blu}, slice type={legno}{rosso}, slice type={coltello}{giallo}, slice type={sedia}{viola}, slice type={caffe}{verde}, pie values/.style={font={\small}}, scale=...

25

You can use the PGFPlots statistics library for this: \documentclass[border=5mm]{standalone} \usepackage{filecontents} \usepackage{pgfplots, pgfplotstable} \usepgfplotslibrary{statistics} \begin{filecontents}{data.csv} dist 1 2 2.5 2 1 3.5 3 1 3 2 1 1 0.5 1 1.5 1 \end{filecontents} \begin{document} \begin{tikzpicture} \begin{axis}[ ybar, ymin=0 ] \...

18

By default, plots always take up the same amount of space (240pt by 207pt). If you want the plots to adjust their height depending on the number of bars, you can define the length of a unit in the y direction, by setting y=0.5cm, for instance. If you then define the bar width to be 0.4cm, there will be no overlap between the bars. Since PGFPlots version 1.7 (...

17

PGFPlots is printing the log transformed x value. To print the non transformed value, set point meta=rawx. (Similarly for ybar, use point meta=rawy to get the raw y value.) Note that bar plots with logarithmic axes are a really bad idea, since the zero point of logarithmic plots is arbitrary and the length of the bar doesn't carry any information. A dot ...

16

There are different ways of getting rid of that big empty space: Decrease the overall width of the plot, moving the groups of bars closer together. You can do this by specifying a unit vector for the x axis. If you add more data, the plot will grow automatically. Keep the overall width of the plot, but move the groups of bars closer together. You can do ...

15

How about something like this: \documentclass{article} \usepackage{amsmath,amssymb} \usepackage{array} \usepackage{xcolor} \def\mybar#1{%% #1s & {\color{red}\rule{#1cm}{8pt}}} \pagestyle{empty} \begin{document} \begin{tabular}{>{$\rhd$ }lrl} Loop at line 151 in divergence & \mybar{3.420}\\ Loop at line 1071 in radiation & \mybar{3.270}\\...

14

You can reverse the order of the legend entries by setting reverse legend: \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[xbar, reverse legend] \addplot coordinates {(2.659244418,1)}; \addlegendentry{A} \addplot coordinates {(18.95781994,1)}; \addlegendentry{B} \end{axis} \end{tikzpicture} \end{...

13

I can think of two things: Anchor the labels at the north east rather than the east. Northeast makes more sense when they are placed diagonally in this way. Reduce the spacing around the labels by setting inner sep=0mm. Result: Code: \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[% xmin=...

12

You can define where the "drawing origin" for logarithmic plots should be by setting log origin to either 0 or infty. If you set it to 0, which is the default, bar plots, comb plots and filled area plots will start from log(1)=0, so in this case the top of the plot. If you set it to infty, the plots will start from the bottom edge of the plot area, which is ...

12

Example using TikZ: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{url} \DeclareUrlCommand\function{\urlstyle{sf}} \usepackage{xcolor} \usepackage{tikz} \usepackage{booktabs} \usepackage{array} \usepackage{multirow} \usepackage{siunitx} \definecolor{chart Idle}{gray}{.6} \definecolor{chart Poor}{RGB}{242,28,28} \...

11

Here is a somewhat roundabout way of achieving this. First add \coordinates at (Plain,3.43) and (Plain, 10.857), and in the lower corners with the rel axis cs coordinate system, then draw lines using these coordinate as reference. Legend entries are added with \addlegendimage. Note that units should not generally be written in italics, so a change there is ...

11

You can make the value of the y coordinate available using the key visualization depends on=y \as \rawy (where \rawy is a macro name you choose). Then you can shift the nodes using shift={(axis direction cs:0,-\rawy)}. Note that you'll have to use axis direction cs because the coordinate system is shifted and scaled at the time when the nodes are placed. \...

11

The error bars aren't aligned with the bars because you're using the ybar interval plot style. I guess this would count as a missing feature, but in your case, you shouldn't actually be using ybar interval anyway, but simply ybar, since you're not trying to plot bars with different data dependent widths. To get a decent looking plot, you can try the ...

10

You can adapt the method from Center nodes near coords in a stacked ybar plot to use nodes near coords for the labels: \documentclass[border=5mm]{standalone} \usepackage{pgfplots} \begin{document} \makeatletter \pgfplotsset{ calculate offset/.code={ \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed} \pgfmathsetmacro\testmacro{(\...

10

nodes near coords alone, without any further customization, results in the desired nodes on top of the bars. This has the disadvantage that your legend description are no longer a standard nodes near coords instruction. The way that pgfplots handles such a case would be to use legend entries, perhaps as in the following example: \documentclass{article} \...

9

Whit pgfplots you can use something like this (not so automatized but still a solution) \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ name=like, scale only axis, xbar, xmin=0, xmax=40, %xbar=2pt, xlabel={likes}, width=5cm, height= 3cm, ytick={1,2,3,4,5}, yticklabels={sa,safda,afa,afa,af}, y tick label ...

9

To get a fixed distance between the centers of the bars, set x=<distance>. To set the width of the bars, set bar width=<distance>. To get a fixed amount of space between the first bar and the left edge of the plot, and between the last bar and the right edge of the plot, set enlarge x limits={abs=<distance>}. To label the bars, set nodes ...

9

you can use ybar=... to shift the bars apart. \documentclass{article} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ ybar=.5cm, ymin=50, ymax=120, height=5cm, width=7cm, xticklabels={enTwitter, +enNewswire}, ylabel=Accuracies (test set), enlarge ...

9

You mean something like this: Above picture is obtained by: \documentclass[border=3mm]{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ title=Title, width=7.8cm, enlargelimits=0.15, legend style={at={(0.5,-0.15)}, anchor=north,legend columns=-1}, ylabel={Pages}, bar width=7mm, y=4mm,...

9

Try that: \documentclass{article} \usepackage{tikz,pgfplots,pgfplotstable} \begin{document} \pgfplotstableread{ % data Label Adequacy Sustainability Integrity Austria 21.87797 5.566584 24.85545 Brazil 20.93009 7.937881 24.33203 Chile 20.41148 21.126529 27.56199 Australia 26.83072 23.823827 28.94545 }\testdata \begin{...

8

In pgfplots you can always access the coordinates of the plot by means of axis cs; in this case, for example, you want to place a label with a number above (axis cs:A,6898.965904) plus the value of the error bar (this is something required otherwise your label will be located inside the error bar). To place a label it is possible to exploit the usual TikZ ...

8

When symbolic coordinates are used, the pattern given by symbolic <x or y> coords should match exactly the pattern given in the coordinates. Hence the whitespace before {Others} should be removed. Moreover, if there are characters such as parentheses or commas in the symbolic coordinate itself that would cause confusion during coordinate parsing of (&...

8

You should do two things: Remove the xtick option Give an explicit data max of 14. The trick is to think of the thirteen bins not as the numbers 1, 2, ..., 13, but as the half-open intervals [1,2), [2,3), ..., [13,14). That's why the data max needs to be 14, not 13. Result: Amended code: \documentclass{article} \usepackage{pgfplots} \usepackage{...

8

You can scale all the tick labels by a common factor using scaled y ticks=base 10:-6 (dividing by 10^6). To switch off the scaling label, set ytick scale label code/.code={}. To add the word million after each label, set yticklabel={\pgfmathprintnumber{\tick} million}: \documentclass{article} \usepackage{pgfplots} \begin{document} \pgfplotsset{compat=1.9} \...

8

Legend box is a TikZ matrix so matrix node options apply to it. \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.10} \begin{tikzpicture}% \begin{axis}[legend style={minimum height=3cm,column sep=4cm}] \addplot {rand};\legend{label} \end{axis} \end{tikzpicture} \end{document}

8

This looks similar, except: missing thumb up/thumb down symbols; negative values; some lesser issues. \documentclass[tikz,border={40pt}]{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[axis x line=top, axis y line=none, bar width=16pt, xmax=25, xmin=-25, ymax=3.5, ymin=-1, width=9cm, ...

Only top voted, non community-wiki answers of a minimum length are eligible