{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PGFPlots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This library uses the LaTeX package [pgfplots](http://ctan.org/pkg/pgfplots) to produce plots. It integrates with IJulia, outputting SVG images to the notebook. This version of PGFPlots requires Julia 0.4 or later."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Installation"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"```\n",
"Pkg.add(\"PGFPlots\")\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In addition, you will need to install the following dependencies if you do not already have them on your system.\n",
"* Pdf2svg. This is required by TikzPictures. On Ubuntu, you can get this by running `sudo apt-get install pdf2svg` and on RHEL/Fedora by running `sudo dnf install pdf2svg`. On Windows, you can download the binaries from http://www.cityinthesky.co.uk/opensource/pdf2svg/. Be sure to add pdf2svg to your path (and restart).\n",
"* Pgfplots (version 1.10 or later). Install using your latex package manager (e.g., texlive or miktex).\n",
"\n",
"Once these things are installed, you should be able to run the following:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"using PGFPlots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Examples"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Linear Plots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can create a very basic plot by passing in vectors of $x$ and $y$ coordinates."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"TikzPictures.TikzPicture(\"\\\\begin{axis}\\\\addplot+ coordinates {\\n(1, 2)\\n(2, 4)\\n(3, 1)\\n};\\n\\\\end{axis}\\n\",\"\",\"\\\\usepackage{pgfplots}\\r\\n\\\\pgfplotsset{compat=newest}\\r\\n\\\\pgfplotsset{every axis legend/.append style={%\\r\\ncells={anchor=west}}\\r\\n}\\r\\n\\\\usepgfplotslibrary{polar}\\r\\n\\\\usetikzlibrary{arrows}\\r\\n\\\\tikzset{>=stealth'}\\r\\n\",true,true)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = [1,2,3]\n",
"y = [2,4,1]\n",
"plot(x, y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The version of the plot function above actually just creates an empty Axis and inserts a Plots.Linear instance containing the data."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Axis(PGFPlots.Plots.Plot[PGFPlots.Plots.Linear(Real[1 2 3; 2 4 1],nothing,nothing,nothing,nothing,nothing,nothing)],nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"axis\")"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Axis(Plots.Linear(x, y))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you create the Axis object explicitly, as done above, then you can set various properties of the axis."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Axis(PGFPlots.Plots.Plot[PGFPlots.Plots.Linear(Real[1 2 3; 2 4 1],nothing,nothing,nothing,\"My Plot\",nothing,nothing)],\"My Title\",\"X\",nothing,\"Y\",nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"axis\")"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pushPGFPlotsOptions(\"scale=1.5\")\n",
"a = Axis(Plots.Linear(x, y, legendentry=\"My Plot\"), xlabel=\"X\", ylabel=\"Y\", title=\"My Title\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The options can be set after the plot `a` is created. Here we rotate the y-label and move the legend by setting the `ylabelStyle` and `legendStyle`:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Axis(PGFPlots.Plots.Plot[PGFPlots.Plots.Linear(Real[1 2 3; 2 4 1],nothing,nothing,nothing,\"My Plot\",nothing,nothing)],\"My Title\",\"X\",nothing,\"Y\",\"rotate = -90\",nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"{at={(1.05,1.0)},anchor=north west}\",nothing,nothing,nothing,nothing,nothing,\"axis\")"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a.ylabelStyle = \"rotate = -90\"\n",
"a.legendStyle = \"{at={(1.05,1.0)},anchor=north west}\"\n",
"a"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This will remove the latest added setting"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"popPGFPlotsOptions();"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And to reset all options, use"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"resetPGFPlotsOptions();"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can set the width and height of the axis."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Axis(PGFPlots.Plots.Plot[PGFPlots.Plots.Linear(Real[1 2 3; 2 4 1],nothing,nothing,nothing,nothing,nothing,nothing)],nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"3cm\",\"3cm\",nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"axis\")"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = Axis(Plots.Linear(x, y), width=\"3cm\", height=\"3cm\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since latex is used to typeset everything, you can use any latex math symbols you want. If you use L\"...\" (as below), you do not have to escape \\ and $."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Axis(PGFPlots.Plots.Plot[PGFPlots.Plots.Linear(Real[1 2 3; 2 4 1],nothing,nothing,nothing,nothing,nothing,nothing)],L\"$\\int_0^\\infty e^{\\pi x}dx$\",L\"$X$\",nothing,L\"$Y$\",nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"axis\")"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Axis(Plots.Linear(x, y), xlabel=L\"$X$\", ylabel=L\"$Y$\", title=L\"$\\int_0^\\infty e^{\\pi x}dx$\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can put multiple plots on the same axis and assign legend entries. You can also pass in functions and their range."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Axis(PGFPlots.Plots.Plot[PGFPlots.Plots.Linear(Real[0.0 0.204082 … 9.79592 10.0; 0.0 0.202668 … -0.362678 -0.544021],\"none\",nothing,nothing,L\"$\\sin(x)$\",nothing,nothing),PGFPlots.Plots.Linear(Real[0.0 0.204082 … 9.79592 10.0; 0.0 0.638877 … 4.42627 4.47214],\"none\",nothing,nothing,L\"$\\sqrt{2x}$\",nothing,nothing)],nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"axis\")"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Axis([\n",
" Plots.Linear(sin, (0,10), legendentry=L\"$\\sin(x)$\"),\n",
" Plots.Linear(x->sqrt(2*x), (0,10), legendentry=L\"$\\sqrt{2x}$\")\n",
"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can change the legend position by setting the legendPos parameter in the axis."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Axis(PGFPlots.Plots.Plot[PGFPlots.Plots.Linear(Real[0.0 0.204082 … 9.79592 10.0; 0.0 0.202668 … -0.362678 -0.544021],\"none\",nothing,nothing,L\"$\\sin(x)$\",nothing,nothing),PGFPlots.Plots.Linear(Real[0.0 0.204082 … 9.79592 10.0; 0.0 0.638877 … 4.42627 4.47214],\"none\",nothing,nothing,L\"$\\sqrt{2x}$\",nothing,nothing)],nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"north west\",nothing,nothing,nothing,nothing,nothing,nothing,\"axis\")"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Axis([\n",
" Plots.Linear(sin, (0,10), legendentry=L\"$\\sin(x)$\"),\n",
" Plots.Linear(x->sqrt(2*x), (0,10), legendentry=L\"$\\sqrt{2x}$\")\n",
" ], legendPos=\"north west\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can do comb plots by setting the style. The style string gets passed directly into PGFPlots, giving you full control over the plots (see PGFPlots [documentation](http://mirror.utexas.edu/ctan/graphics/pgf/contrib/pgfplots/doc/pgfplots.pdf))."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Linear(Real[1.0 2.0 … 9.0 10.0; 0.841471 0.909297 … 0.412118 -0.544021],nothing,nothing,\"ycomb\",nothing,nothing,nothing)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Plots.Linear(1:10, sin(1:10), style=\"ycomb\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also do horizontal comb plots."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Linear(Real[0.841471 0.909297 … 0.412118 0.544021; 1.0 2.0 … 9.0 10.0],nothing,nothing,\"xcomb\",nothing,nothing,nothing)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Plots.Linear(abs(sin(1:10)), 1:10, style=\"xcomb\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also make it smooth."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Linear(Real[1.0 2.0 … 9.0 10.0; 0.841471 0.909297 … 0.412118 -0.544021],nothing,nothing,\"smooth\",nothing,nothing,nothing)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Plots.Linear(1:10, sin(1:10), style=\"smooth\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There is support for constant plots."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Linear(Real[1.0 2.0 … 9.0 10.0; 0.841471 0.909297 … 0.412118 -0.544021],nothing,nothing,\"const plot\",nothing,nothing,nothing)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Plots.Linear(1:10, sin(1:10), style=\"const plot\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Linear(Real[1.0 2.0 … 9.0 10.0; 0.841471 0.909297 … 0.412118 -0.544021],nothing,nothing,\"ybar\",nothing,nothing,nothing)"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Plots.Linear(1:10, sin(1:10), style=\"ybar\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Linear(Real[1.0 2.0 … 9.0 10.0; 0.841471 0.909297 … 0.412118 -0.544021],\"none\",nothing,\"ybar,fill=green\",nothing,nothing,nothing)"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Plots.Linear(1:10, sin(1:10), style=\"ybar,fill=green\", mark=\"none\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can give an axis a log scale by specifying xmode or ymode parameters of Axis:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Axis(PGFPlots.Plots.Plot[PGFPlots.Plots.Linear(Real[0.01 0.02 … 0.99 1.0; 1.02329 1.04713 … 9.77237 10.0],\"none\",nothing,nothing,nothing,nothing,nothing)],nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"log\",nothing,nothing,nothing,\"axis\")"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = Plots.Linear(0.01:0.01:1, 10.^(0.01:0.01:1), mark=\"none\")\n",
"Axis(p, ymode=\"log\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Fill and fill opacity can be handled through the style parameter."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Linear(Real[0 1 … 9 10; 0 1 … 81 100],\"none\",nothing,\"red, fill=blue, fill opacity=0.3\",nothing,nothing,nothing)"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = Plots.Linear(0:10, (0:10).^2, style=\"red, fill=blue, fill opacity=0.3\", mark=\"none\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you want the tick marks to be equal, you can set axisEqual to true (equivalent to axis equal in LaTeX). Note that this will also change the limit sizes, over riding xmax, xmin, ymin, and ymax."
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Axis(PGFPlots.Plots.Plot[PGFPlots.Plots.Linear(Real[0 1 … 9 10; 0 2 … 18 20],nothing,nothing,nothing,nothing,nothing,nothing)],nothing,nothing,nothing,nothing,nothing,nothing,nothing,0,10,nothing,nothing,true,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"axis\")"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = Plots.Linear(0:10, 2*(0:10))\n",
"a = Axis(p, axisEqual=true, xmin=0, xmax=10) # note xmin and xmax are disregarded..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If this flippant disregard of your axis limit authority displeases you, you can set axisEqualImage to true (equivalent to axis equal image). This will leave the limits alone, and let you modify them."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Axis(PGFPlots.Plots.Plot[PGFPlots.Plots.Linear(Real[0 1 … 9 10; 0 2 … 18 20],nothing,nothing,nothing,nothing,nothing,nothing)],nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,true,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,\"axis\")"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = Plots.Linear(0:10, 2*(0:10))\n",
"a = Axis(p, axisEqualImage=true)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can change the size of the markers with the `markSize` argument. The default marker size is 2."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Linear(Real[0 1 … 9 10; 0 2 … 18 20],nothing,10,nothing,nothing,nothing,nothing)"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Plots.Linear(0:10, 2*(0:10), markSize=10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To eliminate the line and only use marks, you can set the `onlyMarks` argument to true."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Linear(Real[0 1 … 9 10; 0 2 … 18 20],nothing,nothing,nothing,nothing,true,nothing)"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Plots.Linear(0:10, 2*(0:10), onlyMarks=true)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Error Bars"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can plot error bars for Linear and Scatter plots. Here we specify an array for the y error."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"TikzPictures.TikzPicture(\"\\\\begin{axis}\\\\addplot+ [\\n, error bars/.cd, \\nx dir=both, x explicit, y dir=both, y explicit]\\ntable [\\nx error plus=ex+, x error minus=ex-, y error plus=ey+, y error minus=ey-\\n] {\\nx y ex+ ex- ey+ ey-\\n1 2 0.0 0.0 1.0 1.0\\n2 4 0.0 0.0 0.3 0.3\\n3 1 0.0 0.0 0.5 0.5\\n};\\n\\\\end{axis}\\n\",\"\",\"\\\\usepackage{pgfplots}\\r\\n\\\\pgfplotsset{compat=newest}\\r\\n\\\\pgfplotsset{every axis legend/.append style={%\\r\\ncells={anchor=west}}\\r\\n}\\r\\n\\\\usepgfplotslibrary{polar}\\r\\n\\\\usetikzlibrary{arrows}\\r\\n\\\\tikzset{>=stealth'}\\r\\n\",true,true)"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = [1,2,3]\n",
"y = [2,4,1]\n",
"plot(x, y, errorBars = ErrorBars(y=[1, 0.3, 0.5]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The y error does not have to be symmetric."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"TikzPictures.TikzPicture(\"\\\\begin{axis}\\\\addplot+ [\\n, error bars/.cd, \\nx dir=both, x explicit, y dir=both, y explicit]\\ntable [\\nx error plus=ex+, x error minus=ex-, y error plus=ey+, y error minus=ey-\\n] {\\nx y ex+ ex- ey+ ey-\\n1 2 0.0 0.0 1.0 0.5\\n2 4 0.0 0.0 0.3 0.1\\n3 1 0.0 0.0 0.5 0.1\\n};\\n\\\\end{axis}\\n\",\"\",\"\\\\usepackage{pgfplots}\\r\\n\\\\pgfplotsset{compat=newest}\\r\\n\\\\pgfplotsset{every axis legend/.append style={%\\r\\ncells={anchor=west}}\\r\\n}\\r\\n\\\\usepgfplotslibrary{polar}\\r\\n\\\\usetikzlibrary{arrows}\\r\\n\\\\tikzset{>=stealth'}\\r\\n\",true,true)"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(x, y, errorBars = ErrorBars(yplus=[1, 0.3, 0.5], yminus=[0.5, 0.1, 0.1]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also specify x error."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"TikzPictures.TikzPicture(\"\\\\begin{axis}\\\\addplot+ [\\n, error bars/.cd, \\nx dir=both, x explicit, y dir=both, y explicit]\\ntable [\\nx error plus=ex+, x error minus=ex-, y error plus=ey+, y error minus=ey-\\n] {\\nx y ex+ ex- ey+ ey-\\n1 2 0.1 0.1 1.0 1.0\\n2 4 0.1 0.1 0.3 0.3\\n3 1 0.05 0.05 0.5 0.5\\n};\\n\\\\end{axis}\\n\",\"\",\"\\\\usepackage{pgfplots}\\r\\n\\\\pgfplotsset{compat=newest}\\r\\n\\\\pgfplotsset{every axis legend/.append style={%\\r\\ncells={anchor=west}}\\r\\n}\\r\\n\\\\usepgfplotslibrary{polar}\\r\\n\\\\usetikzlibrary{arrows}\\r\\n\\\\tikzset{>=stealth'}\\r\\n\",true,true)"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(x, y, errorBars = ErrorBars(y=[1, 0.3, 0.5], x=[0.1, 0.1, 0.05]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can change the style."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"TikzPictures.TikzPicture(\"\\\\begin{axis}\\\\addplot+ [\\n, error bars/.cd, \\nerror bar style = {red,very thick}, x dir=both, x explicit, y dir=both, y explicit]\\ntable [\\nx error plus=ex+, x error minus=ex-, y error plus=ey+, y error minus=ey-\\n] {\\nx y ex+ ex- ey+ ey-\\n1 2 0.0 0.0 1.0 1.0\\n2 4 0.0 0.0 0.3 0.3\\n3 1 0.0 0.0 0.5 0.5\\n};\\n\\\\end{axis}\\n\",\"\",\"\\\\usepackage{pgfplots}\\r\\n\\\\pgfplotsset{compat=newest}\\r\\n\\\\pgfplotsset{every axis legend/.append style={%\\r\\ncells={anchor=west}}\\r\\n}\\r\\n\\\\usepgfplotslibrary{polar}\\r\\n\\\\usetikzlibrary{arrows}\\r\\n\\\\tikzset{>=stealth'}\\r\\n\",true,true)"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(x, y, errorBars = ErrorBars(y=[1, 0.3, 0.5], style=\"red,very thick\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also specify the mark."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"TikzPictures.TikzPicture(\"\\\\begin{axis}\\\\addplot+ [\\n, error bars/.cd, \\nerror mark = {diamond}, x dir=both, x explicit, y dir=both, y explicit]\\ntable [\\nx error plus=ex+, x error minus=ex-, y error plus=ey+, y error minus=ey-\\n] {\\nx y ex+ ex- ey+ ey-\\n1 2 0.0 0.0 1.0 1.0\\n2 4 0.0 0.0 0.3 0.3\\n3 1 0.0 0.0 0.5 0.5\\n};\\n\\\\end{axis}\\n\",\"\",\"\\\\usepackage{pgfplots}\\r\\n\\\\pgfplotsset{compat=newest}\\r\\n\\\\pgfplotsset{every axis legend/.append style={%\\r\\ncells={anchor=west}}\\r\\n}\\r\\n\\\\usepgfplotslibrary{polar}\\r\\n\\\\usetikzlibrary{arrows}\\r\\n\\\\tikzset{>=stealth'}\\r\\n\",true,true)"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(x, y, errorBars = ErrorBars(y=[1, 0.3, 0.5], mark=\"diamond\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can control the style of the plot line along with the error bars."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"TikzPictures.TikzPicture(\"\\\\begin{axis}\\\\addplot+ [\\nred, error bars/.cd, \\nerror mark = {diamond}, error bar style = {black,very thick}, x dir=both, x explicit, y dir=both, y explicit]\\ntable [\\nx error plus=ex+, x error minus=ex-, y error plus=ey+, y error minus=ey-\\n] {\\nx y ex+ ex- ey+ ey-\\n1 2 0.0 0.0 1.0 1.0\\n2 4 0.0 0.0 0.3 0.3\\n3 1 0.0 0.0 0.5 0.5\\n};\\n\\\\end{axis}\\n\",\"\",\"\\\\usepackage{pgfplots}\\r\\n\\\\pgfplotsset{compat=newest}\\r\\n\\\\pgfplotsset{every axis legend/.append style={%\\r\\ncells={anchor=west}}\\r\\n}\\r\\n\\\\usepgfplotslibrary{polar}\\r\\n\\\\usetikzlibrary{arrows}\\r\\n\\\\tikzset{>=stealth'}\\r\\n\",true,true)"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(x, y, style=\"red\", errorBars = ErrorBars(y=[1, 0.3, 0.5], style=\"black,very thick\", mark=\"diamond\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Scatter Plots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A simple scatter plot is just a linear plot with \"only marks\". The following code returns a Linear plot with \"only marks\" selected:"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Linear(Real[1 2 … 9 10; 2 4 … 18 20],nothing,nothing,nothing,nothing,true,nothing)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = 1:10\n",
"y = 2x\n",
"Plots.Scatter(x, y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"PGFPlots gives you the option of picking a color for each scatter point. You can provide a third vector with the desired color values. The following code returns a Scatter plot where points with smaller z-values are blue. Points redden as the z-values increase."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
"PGFPlots.Plots.Scatter(Any[1 2 … 9 10; 2 4 … 18 20; 3 6 … 27 30],nothing,nothing,nothing,nothing,true,nothing)"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z = 3x\n",
"Plots.Scatter(x, y, z)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To add a colorbar, you can set the `colorbar` argument to true."
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"