I have a data file which looks like this:  1   256 2   197 3   190 4   188 5   219 6   169 7   179 8   181 9   182 10  178   where the first column are timesteps and the second column contains the number of iterations an algorithm needed in the corresponding timestep.  I plot this with the first column as the x axis and the second column is the graph. Now I want to add the average amount of iterations over all timesteps and plot it as well.  Is there a way to calculate the mean of a column within pgfplots and use this value in the same plot like this:  \addplot[samples=2] {\meanValue};
121156
I would like to add a straight line to a pgfplot that indicates the mean of the data. For a histogram, this should be a vertical line; for a simple plot, a horizontal line. Now, I do get as far as in the provided minimal working example.  \documentclass{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.9} \begin{filecontents}{data.csv} 1.84919 0.97280 4.78586 3.95797 4.50753 2.52274 5.13984 0.29474 5.39946 4.40204 \end{filecontents} \newcommand*{\manmean}{3.3832} \begin{document}   \begin{tikzpicture}   \begin{axis}     \addplot[hist={bins=6,}, fill=teal, draw=teal!50!black] table[y index=0] {data.csv};     \addplot[teal, ultra thick, dashed] coordinates {(3.3832, 0) (3.3832, 3)};   \end{axis} \end{tikzpicture} % \begin{tikzpicture}   \begin{axis}     \addplot[teal, mark=*] table [x expr=\coordindex+1, y index=0] {data.csv};     \addplot[teal, ultra thick, dashed] coordinates {(1, \manmean) (10, \manmean)};   \end{axis} \end{tikzpicture} \end{document}     However, two issues remain:   the mean needs to be calculated manually the line's start and end need to be entered manually   Really, the line should stretch along the full extend of the axis and touch the borders.  The pgfplots manual mentions /pgfplots/xmin, /pgfplots/xmax, /pgfplots/ymin and /pgfplots/ymax under 4.14.1 Configuration of Limits Ranges. There is also /pgfplots/boxplot/average in 5.11 Statistics. However, I cannot find a way to access these values.  Theoretically, I could calculate the mean using awk. This does not work, however, because pdflatex somehow will not compile with a shell command that uses printf and quotation marks.  \documentclass{standalone} \usepackage{pgfplots} \usepackage{filecontents} \pgfplotsset{compat=1.9} \begin{filecontents*}{data.csv} 1.84919 0.97280 4.78586 3.95797 4.50753 2.52274 5.13984 0.29474 5.39946 4.40204 \end{filecontents*} \begin{document} \begin{tikzpicture}   \begin{axis}     \addplot[teal, mark=*] table [x expr=\coordindex+1, y index=0] {data.csv};     \addplot[teal, ultra thick, dashed, mark=*] shell {awk '{ sum += $1 } END { printf "%i %f\n%i %f\n", 1, sum/NR, NR, sum/NR }' data.csv};   \end{axis} \end{tikzpicture} \end{document}   Note that the argument -shell-escape is required to compile a document that contains shell scripts, e.g. pdflatex -shell-escape mwe-mean-awk.tex.  The error it gives:  Runaway argument? {awk '{ sum += $1 } END { printf "\end {axis} \end {tikzpicture} \end \ETC. ! Paragraph ended before \pgfplots@addplotimpl@shell@opt was complete. &lt;to be read again&gt;                     \par  l.25   ?   Even if this did work, the line would still be too short for a pretty picture.
111606
I use data1 = Table[] in Mathematica 9 (M9) to generate a table of values. The thing is that when I read the data file, there's only one column! How can I plot this data file in LaTeX using pgfplots? Here's a ME  \documentclass[border=1]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=1.5} \begin{document} \begin{tikzpicture}     \begin{axis}             \addplot table {TestTable.csv};      \end{axis} \end{tikzpicture} \end{document}   I also tried TestTable.txt instead of .csv but without any success.  TestTable.csv is generated in M9 with the following code   Export[NotebookDirectory[] &lt;&gt; "TestTable.csv", data1]  where data1 is defined earlier in M9 is some data e.g. numerical integration or similar. A smaller version of data1 in textform (i.e. TestTable.txt) looks like this   1.1 2.3 3.0 4.1 5.3 6.2 7.3 8.4 9.6 10.3
102922
I am using pgfplot to draw graphs in latex. Now this is the problem I am facing:  \begin{tikzpicture}[scale=1] \begin{axis}[ybar,grid=major,bar width=2pt,width=8cm, height=8cm,xmin=1,xmax=540,ymin=1,ymax=240] \addplot [draw=black,fill=green]  table [x=size, y=cluster, col sep=comma] {sim-0.4-0.6.csv}; \end{axis} \end{tikzpicture}   It generates the following graph:    Since, I have values mainly between 0-50 on x-axis, I want to zoom there. After that, values comes around 500. S0, there are no graph points between 50 - 450. How should I do that?
73989
I am new to 'drawing' in LaTeX with pgfplots, tikz, etc. I am trying to plot a Poisson distribution with varying means. Here is what I have tried (based on )  \documentclass{article} \usepackage{pgfplots} \pgfmathdeclarefunction{poiss}{1}{%   \pgfmathparse{(#1^x)*exp(-#1)/(x!)}% } \begin{document} \begin{figure} \begin{tikzpicture} \begin{axis}[every axis plot post/.append style={   mark=none,domain=0:20,samples=20},   axis x line*=bottom,   axis y line*=left,   enlargelimits=upper]   \addplot {poiss(1)};   \addplot {poiss(2)};   \addplot {poiss(3)}; \end{axis} \end{tikzpicture} \end{figure} \end{document}   What happens next is very strange to me; if I plot this with domain=0:20,samples=20, it looks like the following:    However, if I change domain=0:10,samples=10, it looks like the following:    You can see that the higher mean distributions are 'taller' than they should be, depending on the number of samples; the larger the number samples, the more correct the distributions look but obviously a graph going from 0 to 50 on the x-axis with nothing interesting after 10 is no good!  I'm wondering why is this happening, and how can I fix it? Forgive me if it's something painfully obvious. Thanks.
3491
I like TikZ's capability to traverse multiple variables separated by a slash in the foreach (as in the example below). I am looking for something equivalent in PGFplots? I saw in the documentation that say you can't nest the foreach in PGFplots as you can in TikZ, but that only make this kind of feature more important.    Two other small issues:    I like the \x notation so that is why I am using \pgfplotsforeachungrouped. Is there a reason why I should be using pgfplotsinvokeforeach instead?  Also, what is the correct syntax to be able to use a variable to define the list instead of having the actual list in the code. In the following I'd like to be able to reference \ListWithLabels in the foreach.    \documentclass{minimal} \usepackage{pgfplots}  \newcommand*{\ListWithLabels}{-2/a, -1/b, 1/c, 2/d} \newcommand*{\ListWithoutLabels}{-2, -1, 1, 2}  \begin{document} \begin{tikzpicture} \draw [-&gt;][gray, thin](-3,0) -- (3,0) node[blue, right] {$x$};  \draw [-&gt;][gray, thin](0,-3) -- (0,3) node[blue, above] {$y$};  %\foreach \x/\l in \ListWithLabels {  % works \foreach \x/\l in {-2/a, -1/b, 1/c, 2/d} {     \draw [thick, red]         (\x,-2pt) -- (\x,2pt)         node [red, above] {\l}; } \end{tikzpicture}  \begin{tikzpicture} \begin{axis}[     minor tick num=0, axis y line=center, axis x line=middle,      xmin=-3, xmax=3, ymin=-3, ymax=3, xlabel=$x$, ylabel=$y$,     xtick={0},  xticklabels={}     ]  %\pgfplotsinvokeforeach{-2, -1, 1, 2}{             % works %   \addplot [mark=none,color=red, thin, samples=2] %       coordinates{(#1,-0.05) (#1,0.05) }; %}  %\pgfplotsforeachungrouped \x in {\ListWithoutLabels}{  % does not work \pgfplotsforeachungrouped \x in {-2, -1, 1, 2}{    % works     \addplot [mark=none,color=red, thick, samples=2]%         coordinates{ (\x,-0.08) (\x,0.08) }; }   %\pgfplotsforeachungrouped \x/\l in {-2/a, -1/b, 1/c, 2/d}{ % does not work %   \addplot [mark=none,color=red, thin, samples=2]% %       coordinates{ (\x,-0.05) (\x,0.05) } %        node [red, below] {\l}; %}  \end{axis} \end{tikzpicture} \end{document}   Update: I saw  post which explains that the macro in TikZ needs to be not be sourrouned by {}. But that does not work for the PGF commands.  Here is another related post on
116194
Possible Duplicate:          Compiling my document with many PGF Plots, each containing thousands of data points from a CSV file takes too long (minutes). I realize that it does not make sense to have this many data points -- were there, say, a tenth, it would be enough to recreate the same plot on paper.  One of my files, for example, consists of 216000 lines of such a format: 0.000000000000000000e+00 0.000000000000000000e+00  1.388888888888888888e-04 -2.182787284255027771e-11 Of course, that is far too much. I then read the file as:  \documentclass{scrartcl}  \usepackage{pgfplots} \pgfplotsset{compat=1.5.1}  \begin{document}  \begin{tikzpicture}     \begin{loglogaxis}[         \addplot[mark=*, color=red] file {Data/plotXYZ.dat};     \end{loglogaxis} \end{tikzpicture}  \end{document}   Is it possible for the package to take only every x-th line to speed up the compilation process? Or are there other ways to make it (significantly) faster?  I am running Ubuntu and a friend of mine recommended me to write an awk script that would go through a .csv file and retain only every x-th line. However, I have no clue how I would do that, as I have never used awk before. If this would turn out to be the option of choice, could someone help me setting up such a script?
123429
Is it possible to extract data points from moving average data?  In other words, if a set of data only has simple moving averages of the previous 30 points, is it possible to extract the original data points?  If so, how?
106976
I have a file with three columns of data, x, y, r.  # x y r 1 1 0.1 2 2 0.5 3 3 1.2   and so on. I'd like to loop over the rows, and draw a circle at x,y with radius r for each row.  I first thought I'd use pgfplots with customized marks, but I couldn't figure out how to pass the radius parameter into the pgfplot mark handler. Then I thought I'd use tikz and pgf directly, but I couldn't figure out how to reference the values for r inside a draw command sequence.   Any thoughts ? I'd be very grateful for some help.
35194
I use pgfplots for most of my plots. Now I need to add a . Is this possible with pgfplots or any other package?
1595
I have recently discovered the wonderful pgfplots package and I've started coding my Python code to output tabular data of whatever is plotted (at least for simple plots). In my LaTeX source code, I use plot file {../datafiles/data.dat}; and similar commands extensively. All my external figures (yes, I still have some) are in a separate directory that I specify in my preamble using \graphicspath{...}. Is there any equivalent path that TikZ and pgfplots use to search for data files?  I have difficulties searching for an answer to this question, because the word path has such a specific meaning in a TikZ context. I'm using PGF 2.10 and pgfplots 1.5.  I checked in the PGF manual (section 19.4, page 224) and in the pgfplots manual (section 4.2.2, page 25–26) but did not find anything relevant.  MWE:  \documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} \addplot plot file {somedata.dat}; \end{axis} \end{tikzpicture} \end{document}   where somedata.dat contains:  1 2 3 4 5 6 7 8 9 10   Sorry for not adding a MWE earlier, I figured it wasn't needed because the question was obvious.
8905
I was wondering if anyone could point me in the direction of some good sources to learn about user-defined styles in pgfplots? I've been through the pgfplots manual but it seems to only touch on this subject. So far I've been able to define some styles of my own, and call them without any issues, but I'd like to expand on this functionality, and for that I need some more detail about what styles are and aren't capable of, and what the appropriate syntax is. Some of my questions are:  Q1: Can I define nested styles? For example, my preamble defines MyStyle1 like so:  \pgfplotsset{MyStyle1/.style={code-goes-here}}   I then call this style in my document with something like this:  \begin{tikzpicture}     \begin{axis}[MyStyle1]           \addplot[MyStyleA] pseudo-code;     \end{axis}       \end{tikzpicture}   What I'd like to do is have MyStyleA have one definition if the axis uses MyStyle1, and a different definition if the axis is using MyStyle2. Can this be done? How would I go about this?  Q2: How do I overwrite parts of a style? Let's say MyStyle1 includes the line xmin=5, and I apply MyStyle1 to an axis environment as above. I want the minimum x value to instead be 0, but to otherwise use all other settings from MyStyle1. How do I override this for just this axis environment (i.e. not affect any other things that use MyStyle1)?  Q3: Are there any limitations to what I can put in a style? I'm assuming any settings I can put in [] brackets can also be put in a style. Any exceptions or additions to this rule?
4832
I managed to create a simple linear plot with pgfplots-manual (chapter 4.5.1)    Now I want to replace the values of x-axis (1,2,3,4) with text, e.g.Test A, Test B, Test C, Test D. How can I do such a configuration?  MWE:       \documentclass[12pt,ngerman]{article}     \usepackage{pgfplots}     \pgfplotsset{width=7cm,compat=1.10}      \begin{document}      \begin{tikzpicture}     \begin{axis}         [         xlabel={Test},         ylabel={Mean}         ]     \addplot+[sharp plot] coordinates     {(0,18.26) (1,21.47) (2,24.58) (3,24.95)};     \end{axis}     \end{tikzpicture}      \end{document}
110216
In R, it's relatively trivial to perform per pixel calculations based on a raster stack (e.g., get std.dev for each pixel on a 12 layer GeoTIFF). Unfortunately, the speed is less than desirable when working with large rasters.  Recently, I've been trying to use GDAL for this purpose, but I can't seem to get the expression down. I've tried the following, but it doesn't seem to work as advertised (or how I think it should work):  gdal_calc.py -A tmean_monthly_1980.tif --calc="std(A)" --outfile=tstdev_1980.tif --allBands=A --calc="std(A)" --NoDataValue=-9999   In the above example tmean_monthly_1980.tif is a raster composed of 12 layers (Jan-Dec) of mean monthly temperatures in 1980 (stacked using gdal_merge). Although the GDAL command produces an output, the results are definitely not the standard deviation per pixel.  Another option might be to use single band files, but gdal_calc.py appears limited to "only" 26 inputs (A-Z; i.e., "-A file -B file -C file etc."), and the resulting command line/script would be fairly cumbersome when working with large, multi-layered rasters (e.g., time series).  Is there a specific syntax for performing per-pixel raster calculations on a multi-band image using GDAL? If only individual files/bands can be specified using gdal_calc.py, please provide a scripted example using Bash, Python, etc.  Specifically, my goal is to calculate the standard deviation and cv for each pixel in a multi-layer raster stack, or using individual files that make up the same raster stack.  Note: I'm holding out for a GDAL specific answer, but other FOSS solutions are welcomed and will be upvoted, especially if they are relatively compact and adaptable to large number of inputs.
49192
Just for fun, I want to chart my monthly household power consumption year-over-year.  However, I wish to include some reference to monthly temperature so I can determine if my home or behavior is improving, worsening, or holding steady in regards to kWh usage.  The data I am working with:    +----------+--------+-----------+----------------+----------+-----------+------------+ |  Month   | # Days | kWh Usage | Daily kWh Avg. | Avg. Low | Avg. High | Avg. Temp. | +----------+--------+-----------+----------------+----------+-----------+------------+ | Mar 2015 |     32 |      1048 |             33 |       40 |        60 |         50 | | Feb 2015 |     29 |      1156 |             40 |       32 |        54 |         43 | | Jan 2015 |     33 |      1143 |             35 |       38 |        57 |         47 | | Dec 2014 |     30 |       887 |             30 |       39 |        61 |         50 | | Nov 2014 |     29 |       645 |             22 |       45 |        67 |         56 | | Oct 2014 |     29 |       598 |             21 |       60 |        78 |         69 | | Sep 2014 |     32 |       893 |             28 |       70 |        85 |         77 | | Aug 2014 |     30 |       965 |             32 |       72 |        87 |         79 | | Jul 2014 |     29 |       784 |             27 |       72 |        87 |         79 | | Jun 2014 |     32 |      1018 |             32 |       69 |        87 |         78 | | May 2014 |     30 |       702 |             23 |       63 |        82 |         72 | | Apr 2014 |     33 |       722 |             22 |       50 |        71 |         60 | | Mar 2014 |     29 |       830 |             29 |       41 |        62 |         52 | | Feb 2014 |     28 |      1197 |             43 |       32 |        52 |         42 | | Jan 2014 |     33 |      1100 |             33 |       38 |        59 |         49 | | Dec 2013 |     30 |       856 |             29 |       40 |        63 |         51 | | Nov 2013 |     33 |       686 |             21 |       48 |        70 |         59 | | Oct 2013 |     30 |       527 |             18 |       61 |        77 |         69 | | Sep 2013 |     30 |       817 |             27 |       69 |        86 |         77 | | Aug 2013 |     28 |       991 |             35 |       72 |        86 |         79 | | Jul 2013 |     31 |       993 |             32 |       73 |        86 |         79 | | Jun 2013 |     30 |       847 |             28 |       66 |        83 |         74 | | May 2013 |     29 |       605 |             21 |       59 |        76 |         67 | | Apr 2013 |     34 |       791 |             23 |       47 |        66 |         57 | +----------+--------+-----------+----------------+----------+-----------+------------+   I started with a column chart easily comparing month-to-month values:    I envisioned a nice background area or line graph mapped to a secondary (right) vertical axis showing the high/low ranges but realized that would be problematic with the multi-year groupings.  It would be easy with one single year:    I am curious to know if anyone can recommend a way of combining all the yearly data into a single chart with temperature comparisons?  Is there some ratio I could use that could effectively relate the kWh usage to average temperature... or some other display technique I am overlooking... or am I stuck with one chart per year?
14593
I want to do a simple graph, where its points will be assigned by a list (NOT a file) of coordinates.  So, I know, that I can do something like this:  \addplot gnuplot [raw gnuplot, color=blue]{plot "test.dat" };   But I need to use it like this:  \addplot gnuplot [raw gnuplot, color=blue]{plot { (0,0)(1,5)(10,12) } };   It looks pretty easy, but I'm somehow not able to find a single mention of using Pgfplots with gnuplot like this.  So, is it even possible to use it like that? And if it is, then how?
30533
I am trying to plot a set of data points (scatter points not linked to each other), where each point has a different color. The color definition is given by predefined rgb values written in the same file that contains the data.  The following file serves as example:  \usepackage{filecontents} \begin{filecontents}{test.dat}     x   y   RED   GREEN   BLUE     1   11  0.2    0.3    0.5     2   14  0.3    0.3    0.4     4   26  0.1    0.8    0.1     3   39  0.0    0.1    0.9 \end{filecontents}   The x and y columns represent the position of the points I want to plot. The next three columns RED, GREEN and BLUE correspond to the associated color values in rgb format.  What I was trying so far, was to do:  \begin{document}  \pgfplotstableread{test.dat}\test %number of points to be plotted \pgfplotstablegetrowsof{\test} \pgfmathsetmacro{\N}{\pgfplotsretval-1}    \begin{tikzpicture} \begin{axis}[%     xmin=0, xmax=5,     ymin=0, ymax=45,     width=8cm,     height=6cm,     grid=both,     xlabel=Xtest,      ylabel=Ytest,        ]     \foreach \i in {0,...,\N}     {     \definecolor{testcolor}{rgb}{\thisrow{3}, \thisrow{4}, \thisrow{5}}        \addplot[scatter,          only marks,              scatter/use mapped color={draw=none,fill=testcolor},     ]      table [x index = 0,y index = 1]{\test};     } \end{axis} \end{tikzpicture}  \end{document}   But I am unable to fetch a single row value for the color definition. How can I do this ? I also looked at meta options, but the color is defined with a single value (linearly) and I need the three components in the color definition.
34040
Is there a way to incrementally calculate (or estimate) the average of a vector (a set of numbers) without knowing their count in advance?    For example you have a = [4 6 3 9 4 12 4 18] and you want to get an estimate of the average but you don't have all the values at hand so you want to have a running average without keeping all the previous values available.