I'd like to make a bar chart with two basic conditions:  Each bar has a name (not a numeric value) Each bar has its own color  I tried the following, but the result is terribly off. What am I missing? \documentclass[a4paper, 12pt]{article} \usepackage[paperwidth=5in, paperheight=3.2in]{geometry} \usepackage{pgfplots} \pgfplotsset{compat=newest} \geometry{left=0mm, right=3mm,top=6mm, bottom=3mm,}  \begin{document} \begin{tikzpicture}     \begin{axis}[         xbar,         xmin=0,         symbolic y coords = {cat1, cat2, cat3}]          \addplot [fill=red] coordinates {(1,cat1)};         \addplot [fill=green] coordinates {(2,cat2)};         \addplot [fill=blue] coordinates {(3,cat3)};     \end{axis}     \end{tikzpicture} \end{document}
114130
In order to compare three items I use the groupplot command. For each item I have n different criteria to compare.    Is it possible to set the color for each criteria itself? Meaning the first bar in every group goes gray, the second pink etc.. The legend than should contain the n compared criteria.  And... how do I manage to let the whole tikz-picture have a width of 0.9\textwith  \documentclass{standalone} \usepackage{pgfplots,pgfplotstable} \usetikzlibrary{pgfplots.groupplots}  \pgfplotstableread{ nr  fii faa foo a   10  15  12 b   12  18  14 c   13  19  15 d   9   13  10 e   7   11  8 f   10  15  12 }\datatable  \begin{document} \begin{tikzpicture} \begin{groupplot}     [group style={columns=3},         ybar,         ymin=0,         ymax=20,         xtick=\empty,         tickpos=both]  \nextgroupplot[xlabel=fii] \addplot [fill=blue] table [x expr=\coordindex, y=fii] {\datatable}; \nextgroupplot[xlabel=faa] \addplot [fill=green] table [x expr=\coordindex, y=faa] {\datatable}; \nextgroupplot[xlabel=foo] \addplot [fill=red] table [x expr=\coordindex, y=foo] {\datatable};  \end{groupplot} \end{tikzpicture} \end{document}
120836
I am trying to create a grouped bar chart with pgfplots, like this one:    but I can't put the values over the bars, like this one:    My code is:  \documentclass{article} \usepackage{pgfplots} \usepackage{pgfplotstable} \pgfplotsset{compat=newest} \usepackage{caption} \usepackage{polyglossia} \setdefaultlanguage{portuges}  \begin{document}  \begin{figure}[h] \makeatletter \pgfplotsset{     calculate offset/.code={         \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}         \pgfmathsetmacro\testmacro{(\pgfplotspointmeta *10^\pgfplots@data@scale@trafo@EXPONENT@y)*\pgfplots@y@veclength)}         \pgfkeys{/pgf/fpu=false}     },     every node near coord/.style={         /pgfplots/calculate offset,         yshift=-\testmacro     } } %0 - aramente   1 - Às vezes   2 - Quase sempre   4 - Sempre \pgfplotstableread{   %2013-2014    %2012-2013  %2011-2012 0 32        35      20 1 28        45      23 2 30        24      25 3 10        68      70 }\dataset \begin{tikzpicture} \begin{axis}[ybar,         width=12cm,         height=8cm,         ymin=0,         ymax=100,                 ylabel={Percentagem},         xtick=data,         xticklabels = {             Raramente,             Às vezes,             Quase sempre,             Sempre             %Category 5,             %Category 6         },         xticklabel style={yshift=-10ex},         major x tick style = {opacity=0},         minor x tick num = 1,         minor tick length=2ex,         every node near coord/.append style={                 anchor=east,                 rotate=90         }         ] \addplot[draw=black,fill=blue!20, nodes near coords=2013-2014] table[x index=0,y index=1] \dataset; %ano de 2013-2014 \addplot[draw=black,fill=blue!40, nodes near coords=2012-2013] table[x index=0,y index=2] \dataset; %ano de 2012-2013 \addplot[draw=black,fill=blue!60, nodes near coords=2011-2012] table[x index=0,y index=3] \dataset; %ano de 2011-2012 \end{axis} \end{tikzpicture} \captionsetup{justification=centerlast, margin=10ex, labelfont=bf, textfont=it, format=plain, labelformat=default, labelsep=endash, font=small, name=Gráfico\,} \caption{Em sua casa é costume desligar os equipamentos no controlo remoto, deixando-os em standby (modo de “espera”)?}\label{Questao01}  \end{figure}  \end{document}
76947
I have this figure in Excel that I want to replicate in LaTeX.    So far, I have these.    Can anyone help me to get as close as possible to the first figure please? Also, I want to add a legend to the error bars to let the reader know its magnitude.  My MWE:  \documentclass[11pt,paper=a4,BCOR=15mm,bibliography=totoc,DIV=9,final,headings=optiontohead, listof=chaptergapsmall,listof=totoc,numbers=noenddot,openright,parskip=half,titlepage,twoside,]{scrreprt} \usepackage[ngerman,english,]{babel}  \usepackage[onehalfspacing]{setspace}        \usepackage{graphicx} \usepackage{tikz,pgfplots} \usetikzlibrary{intersections, calc} \usepgfplotslibrary{units}   \begin{document}  \begin{figure}[h!] \centering \begin{tikzpicture} [scale=1.23] \begin{axis}[       ybar,         bar width=7pt,         xtick={1,...,9},     ylabel= y values,     xlabel=y values,     enlargelimits=0.05,     ybar interval=0.7,     %       x unit=-,     %       y unit=\si{\frac{kg}{h}},      ]    \addplot     coordinates {(1,4473.317111) (2,7394.47646) (3,6886.499957)      (4,9836.193336) (5,8098.401475) (6,8308.855452) (7,9983.205801)      (8,7617.506648) (9,9617.462814)}; \addplot+[error bars/.cd, y dir=both,y explicit]     coordinates {(1,4342.7395) +- (0,0.05)                 (2,7381.3423) +- (0,0.05)                 (3,6837.375) +- (0,0.05)                 (4,9964.5747) +- (0,0.05)                 (5,7624.083) +- (0,0.05)                 (6,7843.0192) +- (0,0.05)                 (7,9665.1374) +- (0,0.05)                 (8,7266.0779) +- (0,0.05)                 (9,9393.7355) +- (0,0.05)                 }; \legend{x data,y values} \end{axis} \end{tikzpicture} \caption{Figure Caption} \label{fig:plot1} \end{figure}  \end{document}
43936
I am using LaTeX, TikZ and PGFplot in order to automatically generate several series of diagrams, one of which is comprised of bar charts. Each bar in each bar chart may have a unique label and height -- I have used PGFplot before and I know that I can read in coordinates from files, but would it be possible for me to create labels for each bar using textual data stored in a tab-separated file? If so, how would I do this? A simplified example of a file I might use is shown below.  # foo.dat # Label | X-Position | Height  A    1    15 B    2    20 C    3    12 D    4    24   Thanks for your help!
48885
I want to draw arrow with two colors, the resulted arrow should be filled by one color at the top and by other color at the bottom, like the following code do to a rectangle:  \draw[top color=blue,bottom color=green] (0,0) rectangle (2,1);   What should I do?
63423
I created this style that shifts the labels and put them on the bottom of the ybars.  However, I have a problem with the bars that have too short length (for example, see the 8.7 and 5.1 in the example below). I want to check if the values are less than some threshold, or the length of the bar is shorter than the label (number) then change its color.  How can I overlay another label on top of the one in white when the bar is shorter? or maybe change the color of the label to a gradient color? or just overlay the part that is outside of the bar?    \documentclass{standalone}  \usepackage{tikz} \usepackage{pgfplots} \usepackage{pgfplotstable} \usetikzlibrary{calc}  \begin{document} \makeatletter \begin{tikzpicture} \begin{axis}[ ybar, every node near coord/.style={   check for zero/.code={ % If meta=0, make the node a coordinate (which doesn't have text)     \pgfmathfloatifflags{\pgfplotspointmeta}{0}{         \pgfkeys{/tikz/coordinate}     }{}   },   check for zero, color=white, text opacity=1, font=\footnotesize, inner ysep=0.5pt, },% % Bottom nodes  calculate full offset/.code={     \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}     \pgfmathsetmacro\testmacro{((\pgfplotspointmeta-\pgfkeysvalueof{/pgfplots/ymin})*10^\pgfplots@data@scale@trafo@EXPONENT@y)*\pgfplots@y@veclength}     \pgfkeys{/pgf/fpu=false} },% nodes near coords bottom/.style={     every node near coord/.append style={         /pgfplots/calculate full offset,         yshift=-\testmacro,         rotate=90, anchor=west,%I need the rotate text here and not in the          %general style, as the ybar redefines the style     } },% ymin=0, nodes near coords={\pgfmathprintnumber[fixed zerofill,precision=1]{\pgfplotspointmeta}}, nodes near coords bottom, ] \pgfplotstableread{ % set real imag mag 1 8.7 2 5.1 3 91.8367  }\mydata \addplot table[x index=0,y index=1,header=false] {\mydata}; \end{axis} \end{tikzpicture} \makeatother \end{document}   * EDIT *  I need to create some special gradient on each label that is below the bar height. For example, I need to adapt something like  to each label that is not showing. However, I cannot find a way to put the macro in the style section of the codes. Or is there any equivalent solution?
8659
I made a plot but it's not at all what I want. There are two things I'm having trouble with: 1.) The bars should be at the bottom, but there's a space between them and the x-axis. 2.) E1/E4, E2/E5 and E3/E6 should have the same color.  Here's a picture of how it is and how I want it below:   And here's my code:  \documentclass{standalone} \usepackage{pgfplots,pgfplotstable} \begin{document} \begin{tikzpicture} \begin{axis}[ symbolic x coords={E1, E4 (dyn.), E2, E5 (dyn.), E3, E6 (dyn.)}, xtick=data, width=\linewidth, height=6cm ] \addplot[ybar,fill=blue, bar width = 1cm] coordinates {     (E1,   8)     (E2,  15)     (E3,   50)     (E4 (dyn.), 4)     (E5 (dyn.), 17)     (E6 (dyn.), 40)  }; \end{axis} \end{tikzpicture} \end{document}   I hope you can help me. Thanks.
49672
This question centers the Symbology tab in QGIS 3.0.  I'm working with categorical data describing event venues in the Chicago area. This is a point dataset which will be overlayed on a street basemap.   Bars Nighclubs Theatres Parks Restaurants Galleries Other   I would like to use the Symbology tool in the Properties window to display "Bars" specifically in red, and "all other values" (nightclubs, theaters, other, etc.) in yellow.  The attribute field I am using is called "Type"  Fundamentally, I have solved this problem using the following process:   Symbology Column Drop Menu -> Select "Categorized" "Formula" button "Type"  =  'Bars' (syntax) Select "Classify" button Outcome: classifcation of "0" represented in Yellow, and "1" in Red.  "1" = "Bars", "0" = "all other values/anything that is not a bar" Change Legend entry for "1" value to read "Bars" Change Legend entry for "0" value to read "All Other Venues"   Indeed, this process solves the problem of isolating the desired value and representing all other values.  I would however like to clarify... is this the only way to isolate one value and represent all others?  Many of the folks I work with are coming from the ArcMap 9 and 10 environments, which make this process super easy using selectable options in the GUI rather than formulas.    Have I missed a GUI method of completing this task while solving this problem or should I start working with formulas?
49438
So, i'm trying to make a nice ybar plot using pgfplot, but i have some issues i want to solve, hope you can help me.  1) the ybar are not centered on the x value as they should, i mean, the bar for x = 1 start at x=1, so it's centered at x=1.5 which looks a bit odd to me. how do i changed that such that the bar is centered around the values?   (that was the easy question i guess)  2) i have a legend "issue", why do i have this kind of double bar instead of one single bar as it should?  3) the real question: there is 2 tests in my dataset. sometimes the value of test 1 is larger than test 2, sometimes the other way around. I don't want stack bar in this kind of setup, that would look strange. What i want to do, is to overlay the 2 bar but the "top" bar (let's say) is not always the same. How do i say to tikz that it should always put the bar with the high value in the "background" and the bar with the small value in the foreground?  Thanks for you help, i enclosed the output figure I get and a MWE.   \documentclass{article}  \usepackage{tikz} \usetikzlibrary{plotmarks} \usepackage{pgfplotstable} \usepackage{pgfplots}  \usepackage[active,tightpage]{preview}  %generates a tightly fitting border around the work \PreviewEnvironment{tikzpicture}  \begin{document}  \begin{tikzpicture} \begin{axis}[     x tick label style={         /pgf/number format/1000 sep=},     ylabel=ylabelé,     xlabel=xlabel,     enlarge x limits=0.01,     ybar,     bar width=10pt,     xmin = 1,     xmax = 16,     width=8cm,height=7cm,     ytick pos=left,     xtick pos=left,     bar shift = 0pt,     ymode=log, ]  \addplot[fill=red, ybar interval] coordinates{     (1,222898.050000000)     (2,235072.800000000)     (3,241192.450000000)     (4,156585.700000000)     (5,44232.0500000000)     (6,7846.75000000000)     (7,1653.35000000000)};  \addplot[fill=blue, ybar interval]     coordinates{     (1, 455097.750000000)     (2, 101759.350000000)     (3, 67777.1500000000)     (4, 62902.1500000000)     (5, 55631.1500000000)     (6, 39789.6500000000)     (7, 34237.2500000000)     (8, 27603.8000000000)     (9, 23348.3000000000)     (10, 8781.80000000000)     (11, 7717.65000000000)     (12, 3644.70000000000)     (13, 1536.20000000000)     (14, 1440.400000000000)     (15, 1748.95000000000)     (16, 252.150000000000)};  \legend{test1, test2} \end{axis} \end{tikzpicture}     \end{document}
30548
Is it possible to combine a TikZ pattern with a background of a chosen color?  \addplot[black,fill=yellow,pattern=north east lines] ...   yields bars which have black stripes on white (transparent?) background, whereas  \addplot[black,pattern=north east lines,fill=yellow] ...   yields bars which are plain yellow with not stripes at all. Any chance of getting tiger-like bars (black stripes on yellow) without defining an inherently-colored pattern by hand?
88300
I'm trying to draw a bar diagram with 4 value groups each consisting of 5 bars. I think it's a scaling problem, so not all the groups were drawn. I already had a look at the documentation but I couldn't find the right config to make that happen...  \documentclass[tikz, border=10pt]{standalone}  \usepackage{pgfplots}  \pgfplotsset{compat=1.16, x tick label style={font=\tiny,align=center}, y tick label style={font=\tiny},% }  \begin{document} \begin{tikzpicture} \begin{axis}[% ybar,% enlargelimits=0.05,% title={title},% symbolic x coords={a,b,c,d},% xtick={data},% ylabel={y-label},% xlabel={},% xticklabels={ValueGroup 1,ValueGroup 2,ValueGroup 3,ValueGroup 4}, legend style={at={(0.5,-0.15)}, anchor=north,legend columns=-1}, ybar interval=0.7, ]  \addplot coordinates{(a,34) (b,36) (c,70) (d,65)}; \addplot coordinates{(a,45) (b,45) (c,43) (d,43)}; \addplot coordinates{(a,23) (b,32) (c,22) (d,20)}; \addplot coordinates{(a,76) (b,25) (c,35) (d,25)}; \addplot coordinates{(a,22) (b,12) (c,45) (d,34)};  \legend{\tiny{bar 1},\tiny{bar 2},\tiny{bar 3},\tiny{bar 4},\tiny{bar 5}} \end{axis}  \end{tikzpicture} \end{document}
68063
I have this script of plotting bar graph with min(-ve) and max(+ve)    \documentclass[border=5mm]{standalone}  \usepackage{pgfplots}  \pgfplotstableread{ Year    FarMin  FarMax  NearMin NearMax HereMin HereMax 1930    -20     50      -10     30      -15     40 1940    -10     60      -15     60      -20     70 1950    -15     78      -20     20      -32     42 1960    -20     30      -15     40      -20     10 1970    -5      30      -30     40      -15     20 }\datatable   \begin{document}% \begin{tikzpicture}   \begin{axis}[     x tick label style={       /pgf/number format/1000 sep=},       ylabel=Population,       ybar,       enlarge x limits=0.15,       bar width=0.8em,     after end axis/.append code={         \draw ({rel axis cs:0,0}|-{axis cs:0,0}) -- ({rel axis cs:1,0}|-{axis cs:0,0});     }   ]   \addplot +[forget plot] table {\datatable};   \addplot table [y index=2] {\datatable};    \addplot +[forget plot] table [y index=3] {\datatable};   \addplot table [y index=4] {\datatable};    \addplot +[forget plot] table [y index=5] {\datatable};   \addplot table [y index=6] {\datatable};   \legend{Far,Near,Here}   \end{axis} \end{tikzpicture}  \end{document}     But, when I want to plot a graph with positive min values , I'm getting graph which is  starting with zero instead of given positive value.  \documentclass[border=5mm]{standalone}  \usepackage{pgfplots}  \pgfplotstableread{ Year    FarMin  FarMax  NearMin NearMax HereMin HereMax 1930    20     50      10     30      15     40 1940    10     60      15     60      20     70 1950    15     78      20     20      32     42 1960    20     30      15     40      20     10 1970    5      30      30     40      15     20 }\datatable   \begin{document}% \begin{tikzpicture}   \begin{axis}[     x tick label style={       /pgf/number format/1000 sep=},       ylabel=Population,       ybar,       enlarge x limits=0.15,       bar width=0.8em,     after end axis/.append code={         \draw ({rel axis cs:0,0}|-{axis cs:0,0}) -- ({rel axis cs:1,0}|-{axis cs:0,0});     }   ]   \addplot +[forget plot] table {\datatable};   \addplot table [y index=2] {\datatable};    \addplot +[forget plot] table [y index=3] {\datatable};   \addplot table [y index=4] {\datatable};    \addplot +[forget plot] table [y index=5] {\datatable};   \addplot table [y index=6] {\datatable};   \legend{Far,Near,Here}   \end{axis} \end{tikzpicture}  \end{document}     Please help me to plot the graph with positive min values. thanks!
25451
I am trying to use PGFPlots to display a large amount of bars, and I run into the problem that it cuts off the last of them.  MWE:  \documentclass[crop,tikz]{standalone}  \usepackage{pgfplots} \usepackage{pgfplotstable} \pgfplotsset{compat=1.13}  \begin{document}  \pgfplotstableread{ row label runtime 0 1 5264 1 2 2971 2 4 1866 3 8 1384 4 16 1205 5 32 1144 6 64 1109 7 128 1095 8 256 1108 9 512 1178 10 1024 1335 11 2048 1667 12 4096 1588 13 8192 2843 14 16384 5541 15 32768 10985 16 65536 21873 17 131072 43687 18 262144 87064 19 524288 174119 }\mytable   \begin{tikzpicture}   \begin{axis}[         ylabel={runtime (${\mu}s$)},         xticklabels from table={\mytable}{label},         xtick=data,         ymin=0,         ymax=10000,         ybar,         xticklabel style={           anchor=north west,           align=left,           rotate=-45,           font=\tiny,           inner sep=1pt,         }, ] \addplot+ [] table [y=runtime, x expr=\coordindex] {\mytable}; \end{axis} \end{tikzpicture}  \end{document}   Result:    By adding the following to the axis options, I can make all the bars fit. But I need to manually adjust bar width (and xmax)  xmin=-1, xmax=20, bar width=7pt,     Is there a way to handle many bars in a barplot automatically?
109106
I am have a similar Grouped Bar Chart as shown in   and wish to know why there are multiple bars in the legend entry. Is it possible to modify the legend so as to consolidate these bars?
112557
I'm trying to create a 2D plot with a color map using pgfplots.  I've managed to get the overall behaviour that I want, but I would like the color map to be logarithmic, rather than linear.  The best I have managed is to use the meta expr key, but then the color bar shows 1-4 instead of 10^1 through 10^4.  Below is my working example.    \begin{tikzpicture} \begin{semilogyaxis}[colorbar, xlabel = create energy (keV), ylabel = deposit energy (kev), ] \pgfplotstableread{../endep_log_au_30_0_0.csv}\mytable % \addplot+[scatter, only marks, scatter src=explicit, mark=square]  table[x=createEn,y=depEn,meta expr=ln(\thisrow{tot})/ln(10)] {\mytable}; \end{semilogyaxis} \end{tikzpicture}   Is there a way to modify how the labels appear on the colorbar or set it to be logarithmic?  Is there a different way I should be approaching this problem?  (Unfortunately I cannot post an image as a new user)
99007
For an example relation R: A -> B, I have the following TikZ code:  \documentclass[tikz]{standalone} \usepackage{tikz} \usetikzlibrary{shapes,backgrounds,decorations.text,patterns} \usetikzlibrary{plotmarks}  \begin{document} \begin{tikzpicture}   \begin{scope}[mark=*,mark size=1pt] % sets A &amp; B   \draw (0,0) node[ellipse, minimum height=50pt,minimum width=30pt,draw,label=above:A]{};   \draw (2,0) node[ellipse, minimum height=50pt,minimum width=30pt,draw,label=above:B]{}; % draw line and label origin a to c   \draw[-&gt;] plot coordinates {(0,10pt)} (0,10pt) node[above]{a} -- (1.9,16pt); % add end point   \node at (2,16pt) {\pgfuseplotmark{*}}; % add end label   \node[above] at (2,16pt) {c}; % draw line and label origin a to e   \draw[-&gt;] plot coordinates {(0,10pt)} (0,10pt) node[above]{a} -- (1.9,-15pt); % add end point   \node at (2,-15pt) {\pgfuseplotmark{*}}; % add end label   \node[above] at (2,-15pt) {e}; % draw line and label origin b to d   \draw[-&gt;] plot coordinates {(0,-10pt)} (0,-10pt) node[above]{b} -- (1.6,2pt);  % add end point   \node at (1.7,2pt) {\pgfuseplotmark{*}}; % add end label   \node[above] at (1.7,2pt) {d};   \end{scope} \end{tikzpicture} \end{document}   Produces:    Is there a simpler way of accomplishing this in TikZ?  It seems like a lot of work.
8766
I'm trying to draw a grouped bar plot, but with added dots "on top" to signify outliers in the results.  Currently I have:      \begin{figure}[]       \begin{tikzpicture}         \begin{axis}[             width  = 1*\textwidth,             height = 4.5cm,             major x tick style = transparent,             ybar=1*\pgflinewidth,             bar width=13pt,             symbolic x coords={A,B,C,D},             xtick = data,             enlarge x limits=0.25,             ymax=15,             ymin=0,             legend cell align=left,             legend style={                     at={(1,1.05)},                     anchor=south east,                     column sep=1ex             }         ]             \addplot[style={fill=red,mark=none}]                 coordinates {(A, 4.44) (B,0.1) (C,4.37) (D,4.07)};              \addplot[style={fill=green,mark=none}]                 coordinates {(A, 0.4) (B,0.8) (C,0.3) (D,0.5)};              \addplot[style={fill=blue,mark=none}]                 coordinates {(A, 0.2) (B,0) (C,0.9) (D,0.8)};              \addplot[style={fill=yellow,mark=none}]                 coordinates {(A, 9.59) (B,0.2) (C,8.86) (D,8.62)};          \draw node[fill,circle,scale=0.5]{} (axis cs:A,7);         \draw node[fill,circle,scale=0.5]{} (axis cs:B,11);         \draw node[fill,circle,scale=0.5]{} (axis cs:C,3);         \draw node[fill,circle,scale=0.5]{} (axis cs:D,12);          \legend{C1,C2,C3,C4}       \end{axis}     \end{tikzpicture} \end{figure}   This draws the grouped plots etc, but the "dots" always appear at the (0,0) position, ignoring the relative coordinates. See the picture below, where it is close to the "A". Ideally, I'd like to position such a dot above every bar in the graph. How can I properly specify the coordinates?