I plotted a 2d figure of a curve but I also want to show variance of the value with a shaded area around the curve line. How can I do it in pgfplots? Here is my current plot.
123375
I have several curves/datasets (obtained from Monte Carlo simulations) with x-dependent y errors I would like to plot with the errors somehow indicated. Since each curve consists of quite a large number of data points with rather small errors, using ordinary errorbars doesn't seem to be the most informative/aestethic solution. Instead, I think it would be nicer to indicate the error by (local) line thickness (or thickness in the y-direction). It could e.g. be done by plotting y(x)+dy(x) and y(x)-dy(x) and fill between the two curves. But how does one do that (in a reasonably easy way - remember: I have several curves!) in Pgfplots?  My question is maybe somewhat similar to , but I don't know how to do the table manipulations (within Pgfplots) needed in my case.  Here's a simplified example of how my datafiles look:  x y dy 0 2 0.1 1 4 0.5 2 3 0.2 3 3 0.3
109781
I have a graph that consists of x and y from Z/11. Is it possible to programmatically draw the lines that have a slope of 2?  Like from (0,0) to (5,10) and (6,12) would become (6,1) because of modulo 11. Just like the graph below.    For that graph I use the following code. But I have to manually calculate the start and end points.      \begin{tikzpicture}     \coordinate (Origin)   at (0,0);     \coordinate (XAxisMin) at (0,0);     \coordinate (XAxisMax) at (11,0);     \coordinate (YAxisMin) at (0,0);     \coordinate (YAxisMax) at (0,11);      \draw [thick, gray,-latex] (XAxisMin) -- (XAxisMax);% Draw x axis     \draw [thick, gray,-latex] (YAxisMin) -- (YAxisMax);% Draw y axis      \foreach \x in {0,1,...,10}{% Two indices running over each       \foreach \y in {0,1,...,10}{% node on the grid we have drawn          \node[draw,circle,inner sep=1pt,fill] at (\x,\y) {};             % Places a dot at those points       }     }      \draw [thin, blue,-latex] (Origin) -- (5,10);       \draw [thin, blue,-latex] (6,1) -- (10,9); \end{tikzpicture}
10423
I want to hatch the area under a curve (graph of a function) with oblique lines on an interval (to illustrate the function's integral on that interval). This can be done elegantly in gnuplot...   ...but I simply cannot reproduce this with pgfplots. The only solution I managed to find with google is the use of the patterns tikz library, however it is unacceptibly ugly:    I'm not aware of any way to alter the color, line width and - especially - the distance between the hatching lines when patterns library is employed. Is there any way to set it? (So that I can change it to resemble the gnuplot version.)  Or, should I choose a completely different approach to reproduce the gnuplot-style hatching...?  Also note that   pgfplots changes the color of the x-axis to red on the interval (which is not a critical problem, of course, but not elegant). the legend for the filling is much more logical in case of gnuplot. Can I reproduce it with pgfplots?   Here is the code I currently use:  \begin{figure}[ht!] \centering \begin{tikzpicture}     \begin{axis}[xmin=-4,xmax=4,xlabel={z},ymin=0,ymax=1]      \addplot[color=red,domain=-4:4,samples=100] {1/sqrt(2*pi)*exp(-x^2/2)};     \addlegendentry{z}     \addplot[color=red,fill=red, pattern=north east lines,  domain=0:1,samples=100] {1/sqrt(2*pi)*exp(-x^2/2)} \closedcycle;     \addlegendentry{Interval}     \end{axis} \end{tikzpicture} \end{figure}
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?
65116
I have two Guassian distribution curves, as shown here and I am attempting to color the areas under the curves as well as the intersection between them, like here:    I assumed fillbetween would be the appropriate tool here, but that produced some strange results. Below is the code  \begin{tikzpicture}     \begin{axis}[     axis lines=left,     domain=0:10,      samples=100,     ymin=0,     xtick=\empty,     ytick=\empty,     enlargelimits=false,      clip=false,     ]      \addplot [thick, orange, name path=cat] {gauss(x, 3, 1)} node[pos=0.3, above]{cat};     \addplot [thick, purple!70!black, name path=puma] {gauss(x, 5, 0.5)} node[pos=0.5, above right] {puma};      \path[name path=axis] (axis cs:0,0) -- (axis cs:10,0);      \addplot[         thick,         color=orange,         fill=yellow,         fill opacity=0.25     ]     fill between[         of=cat and axis     ];      \addplot[         thick,         color=purple!70!black,         fill=purple!70!black,         fill opacity=0.25     ]     fill between[         of=puma and axis     ];      \addplot[         thick,         color=white,         fill=blue,         fill opacity=0.25     ]     fill between[         of=cat and puma     ];     \end{axis} \end{tikzpicture}   which produces this:    Every other answer I've found either miraculously makes fillbetween work or avoids it entirely (usually in ways that seem more complicated than is necessary for a simple task such as this).   Can anyone explain to me what is missing to make fillbetween achieve the desired results or recommend a clean alternative? Thanks in advance.
121788
To display a sensitivity analysis I want to produce a . In the plot a specific base case value is compared to the values produced after changing parameters in the model. I started from this . With this I was able to get this MWE:   \usepackage{pgf} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{positioning} \usetikzlibrary{calc} \usetikzlibrary{intersections,backgrounds} \usetikzlibrary{decorations.pathmorphing}  \pgfplotsset{     TornadoPlot/.style={% Overall settings         width = 1\textwidth,     line width=1pt,     tick style={line width=0.8pt},     xmin = -50, xmax = 50,     xtick       = {-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50},     xticklabels = {-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50},     xmajorgrids = true,     minor x tick num = 1,     tick align = outside,     xtick pos = left, ytick pos = left,     xbar, bar shift=0pt,     height = 7cm,     enlarge y limits = 0.1, ytick = {0,1,2,3,4,5,6},     nodes near coords={         \pgfkeys{/pgf/fpu=true}%         \pgfmathparse{\pgfplotspointmeta}%         \pgfmathprintnumber{\pgfmathresult}     },     nodes near coords align = {horizontal},     before end axis/.code={         \draw ({rel axis cs:0,0}-|{axis cs:0,0}) -- ({rel axis cs:0,1}-|{axis    cs:0,0});     }              } }  \begin{document} \begin{tikzpicture}     \begin{axis}[TornadoPlot, legend style={at={(0.975,0.25)}}]             \addplot[fill=green!40] coordinates{(-3.5,0) (-16,1) (-17.5,2) (-19,3) (-34,4) (-27,5) (-22,6)};             \addplot[fill=red!40] coordinates{(4,0) (19,1) (12.5,2) (28.5,3) (34,4) (82,5) (38,6)};             \legend{upside, downside}      \end{axis} \end{tikzpicture} \end{document}   However, one of the bars (82, 5) has a positive x value that is outside the range of the domain of the plot. Can I restrict the length of that bar and force a break, while still displaying the original value of x? I have seen  for vertical bar-charts, but so far I have not been able to reproduce this for my tornado plot.
34295
Basically, I'm just trying to plot a curve over my histogram for the weight of a few students.   lines(density(weight), lwd = 2, col = "red")   However, what I get is a line on the bottom of the graph. I suppose the density has to be such that the integral of the curve is 1. What command should I be using instead of density, if I want to have a fitting curve for the histogram?
90733
I am trying to draw the inequality plot of this inequality but did not mange to find a way. The plot I want is similar to the one that Mathematica produces. Anybody can help?     I tried this command   \addplot3 [surf,shader=interp,samples=45, domain=-2:6, y domain=-2:6] {(3*sqrt(x^2+y)+sqrt(4*x^3-3*x^2+y)-4)/(sqrt(y+1)+sqrt(3)*sqrt(4*x^3+3*y-  1)-4)};   and then view={0}{90} but it takes a lot of time to compile and I guess there should be a way to produce a 2D plot rather than changing the angle of a 3D plot.
77586
Unable to fill color in the intersection region of $y =\sqrt{x}, y =x , using tikz by the given code.  Please help, thanks  \documentclass{article} \usepackage{tikz,pgfplots} %\usepackage[x11names]{xcolor} \usepackage{tikz} \usetikzlibrary{intersections} \pgfdeclarelayer{bg}    % declare background \pgfsetlayers{bg,main}  % order of layers (main = standard layer) \pgfplotsset{compat=1.13} \usepackage{amsmath} \usetikzlibrary{positioning}      \begin{document}      \begin{tikzpicture}[domain=0:2, scale = 0.75, dot/.style={circle,fill,inner sep=1pt}]     \draw(-4,0)--(4,0);     \draw (0,-4)--(0,4);      \draw(0,0)--(3,3);     %\draw[black, line width = 0.50mm]   plot[smooth,domain=0:2] (\x, {\sqrt{\x}});      \draw[blue,line width = 0.50mm]   plot[smooth,domain= 0:2,variable=\y]     ( {3(\y)^2},\y);     \draw(1,0)--(1,1);     %\draw[black, line width = 0.50mm]   plot[smooth,domain= -2:2] (\y,  {(\y)^2});     \draw(2,3)node($y=x^2$){$y=x$};     \draw(5,2)node($x=y^2$){$\sqrt{x}=y$};     \draw [left=.2cm](0,0)node(o){O};     \draw[right=.1cm](1,1)node(a){A};       \begin{pgfonlayer}{bg}    % select background     \clip plot[smooth,domain=0:2] (\x, {\x});     \fill[red]  plot[smooth,domain= 0:2,variable=\y] ({(\y)^2},\y);     \end{pgfonlayer}     \end{tikzpicture}  \end{document}
20986
I have a function defined as:     How can I graph that using functions instead of coordinates? I'm currently working with pgfplots but I'm open to something else if it's better.
118159
I am trying to plot a graph using tikz, but I can't seem to be able to highlight the areas between the curves. The result should look something like this:    This is the code I have so far:     \begin{center} \begin{tikzpicture}[scale=0.8]  \draw[-&gt;] (0,-0.5) -- (0,4.5) node[anchor=east] {}; \draw[-&gt;] (-0.5,0) -- (9,0) node[anchor=north] {}; \draw   (1,-0.2) node[anchor=north] {$a$}         (8,-0.2) node[anchor=north] {$b$}                ; \filldraw[fill=black!10](1,0)--(1,2)--(8,2)--(8,0); \draw [](1,3) parabola bend (2.5,1.5)(4.2,2.4);  \draw [](4.2,2.4) parabola bend (5.5,3)(8,0);  \draw[] (1,0)--(1,3); \end{tikzpicture} \end{center}   The end result I would like to achieve is to have C and D higlighted in orange, while A and B in a dark grey. Don't worry about the axes labels or else, I mostly need help with the shading.  Thanks in advance!!
82379
I am trying to plot a function but something is incorrectly written... Could anyone please help me?  \documentclass[12pt,a4paper]{article} \usepackage{amsmath, tikz} \usepackage[margin=3cm]{geometry} \usepackage{pgfplots}      \begin{document}  \begin{tikzpicture}[scale=0.45] \draw[-&gt;] (-1,0) -- (10,0) node[below] {$x$}; \draw[-&gt;] (0,-1) -- (0,10) node[above] {$y$}; \draw[dotted] (1.4,3.33) -- (1.4,0); \draw[dotted] (0,3.33) -- (1.4,3.33)  node[left = 0.65cm] {$\frac{10}{3}$}; \draw [domain=0.1:10] plot (\x,{2/(\x-0.8)}) node[right] {$f(x)=\frac{10}{5x-4}$}; \end{tikzpicture} \end{document}
24322
If X and Y are independent random variables both with the same mean (0) and variance, how about $X^2$ and $Y^2$? I tried calculating E($X^2Y^2$)-E($X^2$)E($Y^2$) but haven't been able to get anywhere.
13276
I would like to draw an arc between to lines in a pgfplots picture using axis cs. My first attempt is as follows:      \documentclass[12pt,a4paper]{article}     \usepackage{pgfplots}      \pgfplotsset{compat=newest}      \begin{document}      \begin{center}     \begin{tikzpicture}         \begin{axis}[xmin=-8,xmax=8,xtick={-8,-6,...,8},             ymin=-8,ymax=8,ytick={-8,-6,...,8},grid=major             ,view={0}{90},x post scale={2},y post scale=2             ]         \addplot[black,thin,domain=0:8]{0};         \addplot[black,thin,domain=0:8]{2.3962931*x};         \draw [-&gt;] (axis cs:2,0) arc [radius=17mm,start angle=0,end angle=64.3];     \end{axis}     \end{tikzpicture}     \end{center}      \end{document}   However, the value of the radius and angle needed to be determined via trial and error. Hence, if I change the scaling (as used with x post scale and y post scale) then the arc does not display correctly.  Clearly, I have missed something and there should be a straight forward way to achieve my aims. I can change the arc to a circle (set radius=2 (with no units)) and I get what I expect and it scales.  Any insights would be much appreciated.  Peter Johnston.
41267
I need to plot f(x) = 1 / x in LaTeX and am trying to with Tikz. I haven't found a way to set the vertical range, so the values go out of bound around x=0.  Using gnuplot directly doesn't seem to be an option because the fix presented  fails.  \begin{frame}     \begin{tikzpicture}         \draw[-&gt;] (-10, 0) -- (10, 0) node[right] {$x$};         \draw[-&gt;] (0, -10) -- (0, 10) node[above] {$y$};         \draw[color=red, domain=-10:10] plot[id=x] function{1/x} node[right] { $f(x) = x$ };     \end{tikzpicture} \end{frame}   I'm not set on Tikz, if there are other options I am open to them.
18404
When i plot the graph of $(x^2+x+1)/(x+1)$, there appears to be a solid vertical line in the plot which happens to be the vertical asymptote, is there a way to make that line dotted and also include the oblique asymptote in a similar fashion?  \documentclass{article} \usepackage{amsmath} \usepackage{pgfplots}  \begin{document} \begin{tikzpicture} \begin{axis}[     axis lines = center,     xlabel = $x$,     ylabel = {$y$},     xmax = {5},     xmin = {-5},     ymax = {5},     ymin = {-5},     legend pos = outer north east ] \addplot [     domain=-10:10,      samples=100,      color=black, ] {(x^2+x+1)/(x+1)}; \addlegendentry{2 turning points} \end{axis} \end{tikzpicture} \end{document}
88334
See this example code:  \documentclass{article}  \usepackage{pgfplots} \pgfplotsset{compat=1.10} \begin{document}   \begin{tikzpicture}     \begin{axis}[                  xmin=-0.1,                  xmax=1.1,                  ymin=-1.1,                  ymax=1.1,                  domain=0:1,                  samples=30                 ]       \addplot[blue] {sqrt(x)};       \addplot[purple] {-sqrt(x)};     \end{axis}   \end{tikzpicture} \end{document}   The result appears acceptable far from zero, but near zero it's too much undersampled:    Increasing samples value makes the plot nice, but it considerably slows down processing. As a workaround I could just plot the inverse in a parametric plot (i.e. (y^2,y)), but in my actual code it'd require quite a bit of additional work.  Is there a way to provide a custom sampling function or specify different density of samples in different parts of the domain?