using PGFPlots x = [1,2,3] y = [2,4,1] plot(x, y) print(tikzCode(x, y)) Axis(Plots.Linear(x, y)) pushPGFPlotsOptions("scale=1.5") a = Axis(Plots.Linear(x, y, legendentry="My Plot"), xlabel="X", ylabel="Y", title="My Title") a.ylabelStyle = "rotate = -90" a.legendStyle = "at={(1.05,1.0)}, anchor=north west" a print(tikzCode(a)) popPGFPlotsOptions(); resetPGFPlotsOptions(); Axis(Plots.Linear(x, y), width="3cm", height="3cm") Axis(Plots.Linear(x, y), xlabel=L"$X$", ylabel=L"$Y$", title=L"$\int_0^\infty e^{\pi x}dx$") Plots.Linear(x->sqrt(2*x) + sin(x), (0,10), xbins=51) Axis([ Plots.Linear(sin, (0,10), legendentry=L"\sin(x)"), Plots.Linear(x->sqrt(2*x), (0,10), legendentry=L"\sqrt{2x}") ]) Axis([ Plots.Linear(sin, (0,10), legendentry=L"\sin(x)"), Plots.Linear(x->sqrt(2*x), (0,10), legendentry=L"\sqrt{2x}") ], legendPos="north west") Axis([ Plots.Linear(sin, (0,10), style="red", legendentry=L"\sin(x)"), Plots.Linear(x->sqrt(2*x), (0,10), style="blue, forget plot"), Plots.Linear(x->3exp(-x), (0,10), style="green", legendentry=L"3 \exp{-x}") ]) Plots.Linear(1:10, sin.(1:10), style="ycomb") Plots.Linear(abs.(sin.(1:10)), 1:10, style="xcomb") Plots.Linear(1:10, sin.(1:10), style="smooth") Plots.Linear(1:10, sin.(1:10), style="const plot") Plots.Linear(1:10, sin.(1:10), style="ybar") Plots.Linear(1:10, sin.(1:10), style="ybar,fill=green", mark="none") p = Plots.Linear(0.01:0.01:1, 10 .^(0.01:0.01:1), mark="none") Axis(p, ymode="log") p = Plots.Linear(0:10, (0:10).^2, style="red, fill=blue, fill opacity=0.3", mark="none") p = Plots.Linear(0:10, 2*(0:10)) Axis(p, axisEqual=true, xmin=0, xmax=10) # note xmin and xmax are disregarded... p = Plots.Linear(0:10, 2*(0:10)) Axis(p, axisEqualImage=true) Plots.Linear(0:10, 2*(0:10), markSize=10) Plots.Linear(0:10, 2*(0:10), onlyMarks=true) Plots.DiscreteLinear([3,1,4,1,5,9,2,6,5]) Plots.DiscreteLinear([3,1,4,1,5,9,2,6,5]; start=0, style="no marks") Axis([ Plots.Linear(x->sin(x), (0,2)), Plots.Linear(x->abs(1.5*sin(2x)^2), (0,2)) ]) Axis([ Plots.Linear(x->sin(x), (0,2)), Plots.Linear(x->abs(1.5*sin(2x)^2), (0,2)) ], style="stack plots=y") Axis([ Plots.Linear(x->sin(x), (0,2), closedCycle=true), Plots.Linear(x->abs(1.5*sin(2x)^2), (0,2), closedCycle=true) ], style="stack plots=y, area style, enlarge x limits=false", ymin=0) x = [1,2,3] y = [2,4,1] plot(x, y, errorBars = ErrorBars(y=[1, 0.3, 0.5])) plot(x, y, errorBars = ErrorBars(yplus=[1, 0.3, 0.5], yminus=[0.5, 0.1, 0.1])) plot(x, y, errorBars = ErrorBars(y=[1, 0.3, 0.5], x=[0.1, 0.1, 0.05])) plot(x, y, errorBars = ErrorBars(y=[1, 0.3, 0.5], style="red,very thick")) plot(x, y, errorBars = ErrorBars(y=[1, 0.3, 0.5], mark="diamond")) plot(x, y, style="red", errorBars = ErrorBars(y=[1, 0.3, 0.5], style="black,very thick", mark="diamond")) x = 1:10 y = 2x Plots.Scatter(x, y) z = 3x Plots.Scatter(x, y, z) p = Plots.Scatter(x, y, z) a = Axis(p, colorbar=true) print(tikzCode(a)) z = ["a", "a", "a", "b", "b", "b", "b", "c", "c", "c"] sc = "a={mark=square,blue}, b={mark=triangle,red}, c={mark=o,black}" Plots.Scatter(x, y, z, scatterClasses=sc) Plots.Scatter(x, y, z, scatterClasses=sc, legendentry=["A", "B", "C"]) Axis(Plots.Scatter(x, y, z, scatterClasses=sc, legendentry=["A", "B", "C"]), style="legend columns = -1", legendPos="north west") d = randn(100) a = Axis(Plots.Histogram(d, bins=10), ymin=0) print(tikzCode(a)) Axis(Plots.Histogram(d, bins=20, cumulative=true, density=true), ymin=0) Axis(Plots.Histogram(d, bins=10, style="red, fill=red!10"), ymin=0, ylabel="Counts") Axis(Plots.Histogram(d, discretization=:auto), ymin=0) using Random discretizations = [:default, # use PGFPlots for small data sizes and :auto for large :pgfplots, # use the PGFPlots histogram function (uses nbins, which defaults to 10) :specified, # use Discretizers.jl but with the specified number of bins (which defaults to 10) :auto, # max between :fd and :sturges. Good all-round performance :fd, # Freedman Diaconis Estimator, robust :sturges, # R's default method, only good for near-Gaussian data :sqrt, # used by Excel and others for its simplicity and speed :doane, # improves Sturges’ for non-normal datasets. :scott, # less robust estimator that that takes into account data variability and data size. ] Random.seed!(0) data = [randn(500).*1.8 .+ -5; randn(2000).*0.8 .+ -4; randn(500).*0.3 .+ -1; randn(1000).*0.8 .+ 2; randn(500).*1.5 .+ 4; ] data = filter!(x->-15.0 <= x <= 15.0, data) g = GroupPlot(3, 3, groupStyle = "horizontal sep = 1.75cm, vertical sep = 1.5cm") for discretization in discretizations push!(g, Axis(Plots.Histogram(data, discretization=discretization), ymin=0, title=string(discretization))) end g p = Plots.BarChart(["a", "b"], [1,2]) print(tikzCode(p)) Plots.BarChart([3,4,5,2,10]) Plots.BarChart(["cat", "dog", "cat", "cat", "dog", "mouse"]) Plots.BarChart([L"x", L"x^2", L"x^2", L"sin(x)", "hello world"]) Axis(Plots.BarChart(["potayto", "potahto", "tomayto", "tomahto"], [1,2,3,4], style="cyan"), xlabel="vegetables", ylabel="counts", style="bar width=25pt") Plots.BarChart(["a", "b", "c"], [2, 3, 5], errorBars=ErrorBars(y=[0.5, 0.7, 1.5])) f = (x,y)->x*exp(-x^2-y^2) p = Plots.Image(f, (-2,2), (-2,2)) print(tikzCode(p)) Plots.Image(f, (-2,2), (-2,2), zmin=-1, zmax=1) Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.GrayMap(invert = true)) Plots.Image(f, (-2,2), (-2,2), colorbar = false) Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.Distinguishable(3)) Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.Distinguishable(4)) Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.Distinguishable(4, invert=true)) Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.Named("Blues")) using Colors cm = colormap("RdBu") Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.RGBArrayMap(cm)) Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.Named("Jet")) Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.Brew("Set1", 3)) Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.Brew("Set1", 3, invert=true)) Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.RGBArrayMap([RGB(1.,0.,0.),RGB(0.,1.,0.), RGB(0.,0.,1.)])) Plots.Image(f, (-2,2), (-2,2), colormap = ColorMaps.RGBArrayMap([RGB(1.,0.,0.),RGB(0.,1.,0.), RGB(0.,0.,1.)], interpolation_levels=500)) A = [1 3; 2 10] Plots.Image(A, (-2,2), (-2,2)) p = Plots.Patch2D([0 1 2 1 2 3 2 3 4; # x 0 1 0 1 0 1 0 1 0]) # y p = Plots.Patch2D([0 1 2 1 2 3 2 3 4; # x 0 1 0 1 0 1 0 1 0; # y 0.2 0 1 0 1 0 1 0 0.5]) # color p = Plots.Patch2D([0 1 2 1 2 3 2 3 4; # x 0 1 0 1 0 1 0 1 0; # y 0.2 0 1 0 1 0 1 0 0.5], # color shader = "interp") p = Plots.Patch2D([0 1 2 1 2 3 2 3 4; # x 0 1 0 1 0 1 0 1 0; # y 0.2 0 1 0 -1 0 0.5 1 0.5], # color shader = "interp") p = Plots.Patch2D([0 1 1 0 1 2 2 1 1 2 2 1; # x 0 0 1 1 0 0 1 1 1 1 2 2; # y 0.2 0 1 1 0 -1 0 1 0.5 1 0.5 0], # color shader = "interp", patch_type="rectangle") print(tikzCode(p)) x = randn(10000)*2 .+ 1 y = randn(10000) .- 2 Plots.Histogram2(x, y) Plots.Histogram2(x, y, xmin=-3, xmax=3, ymin=-3, ymax=3, zmin=-1, colormap=ColorMaps.Named("Jet")) Plots.Histogram2(x, y, xmin=-3, xmax=3, ymin=-3, ymax=3, zmin=5, zmax=15, colormap=ColorMaps.Named("Jet")) Axis(Plots.Histogram2(x, y, density=true, xmin=-3, xmax=3, ymin=-3, ymax=3), axisEqualImage=true) Plots.Histogram2(x, y, density=true) Plots.Histogram2(x, y, zmode="log") p = Plots.Histogram2(x, y, zmode="log", zmin=1.) print(tikzCode(p)) x = randn(10000).+1.0 y = randn(10000) edges_x = [-3.0,-1.0,0.0,0.5,0.75,1.0,1.25,1.5,2.0,3.0] edges_y = range(-3.0,stop=3.0,length=11) p = Plots.Histogram2(x, y, edges_x, edges_y, density=true, style="colormap/blackwhite") Axis(p, enlargelimits=0) Plots.Contour(f, (-2,2), (-2,2)) Plots.Contour(f, (-2,2), (-2,2), levels=-0.4:0.1:4) Plots.Contour(f, (-2,2), (-2,2), number=20) Plots.Contour(f, (-2,2), (-2,2), style="very thick") x = range(-2,stop=2) y = range(-2,stop=2) A = Float64[f(xi, yi) for xi in x, yi in y] Plots.Contour(A, x, y) Plots.Contour(randn(11,11), 0:10, 0:10) Plots.Contour(f, (-2,2), (-2,2), contour_style="draw color=cyan", style="dashed") h(x,y) = [exp(-x^2-y^2)*(1-2*x^2), exp(-x^2-y^2)*(-2*x*y)] Plots.Quiver(h,(-2,2),(-2,2)) h2(x,y) = [exp(-x^2-y^2)*(1-2*x^2), exp(-x^2-y^2)*(-2*x*y)] Plots.Quiver(h2,(-2,2),(-2,2), style="-stealth'") Plots.Quiver(h,(-2,2),(-2,2), normalize=false) A = [1 3; 2 10] p = Plots.MatrixPlot(A) print(tikzCode(p)) A = rand(50,50) Plots.MatrixPlot(A) Plots.MatrixPlot(A,(-2,2),(-2,2)) Plots.MatrixPlot(A,(-2,2),(-2,2),colormap = ColorMaps.Named("Jet")) cm = ColorMaps.RGBArrayMap([RGB(1.,0.,0.),RGB(1.,1.,1.), RGB(0.,0.,1.)], interpolation_levels=500) Plots.MatrixPlot(A,(-2,2),(-2,2),colormap = cm) A[20:30,20:30] .= NaN Plots.MatrixPlot(A,(-2,2),(-2,2),colormap = cm) A = rand(120,120) Plots.MatrixPlot(A,(-2,2),(-2,2),colormap = cm) # generate 1000 samples d = randn(1000) # try out histograms with a variety of different number of bins bins = [3 10 50 1000] g = GroupPlot(2,2) # create a 2 x 2 group plot for i = 1:length(bins) push!(g, Axis(Plots.Histogram(d, bins=bins[i]), ymin=0)) end g g = GroupPlot(2, 2, groupStyle = "horizontal sep = 3cm") # create a 2 x 2 group plot for i = 1:length(bins) push!(g, Axis(Plots.Histogram(d, bins=bins[i]), ymin=0)) end g #Create the first axis and add to it two lines a1 = PGFPlots.Axis(style="width=10cm, height=10cm, grid=both"); push!(a1, PGFPlots.Linear([1,2],[10, 10], style="blue")) push!(a1, PGFPlots.Linear([1,2],[10, 3], style="red")) #Create another axis with smaller width. #xshift and yshift are used to position the axis. a2 = PGFPlots.Axis(style="width=4cm, xshift=1cm, yshift=1cm", title="xy reflection"); push!(a2, PGFPlots.Linear([10, 10], [1,2], style="no marks, blue, thick")) push!(a2, PGFPlots.Linear([10, 3] , [1,2], style="no marks, red, thick")); #Group the two axes together as a list [a1, a2] Axis([ Plots.Image(f, (-2,2), (-2,2)), Plots.Node(L"\sqrt{2}",1,0) ]) Axis([ Plots.Image(f, (-2,2), (-2,2)), Plots.Node(L"\sqrt{2}",-1,0,style="yellow"), Plots.Node("Hi there!",1,0,style="right") ]) Axis([ Plots.Image(f, (-2,2), (-2,2)), Plots.Node(L"\sqrt{2}",0.9,0.9,axis="axis description cs") ]) p1 = Plots.Circle(5,5,5) p2 = Plots.Ellipse(5,5,3,5) Axis([p1,p2], xmin=0,ymin=0,xmax=10,ymax=10) a = Axis([p1,p2], xmin=0,ymin=0,xmax=10,ymax=10, hideAxis=true) print(tikzCode(a)) t = rad2deg.(range(0,stop=5pi,length=60)) x = sind.(t) y = cosd.(t) z = 2t/(5pi) p = Plots.Linear3(x, y, z, mark="none") Axis(p, xlabel="x", ylabel="y", zlabel="z") Axis(p, view="{60}{30}", xlabel="x", ylabel="y", zlabel="z") angles = [0,90,180,270] radii = ones(4) p = Plots.Linear(angles, radii) PolarAxis(p) SmithAxis([ PGFPlots.SmithCircle(1.0, 1.0, 2.0, style="blue"), PGFPlots.SmithCircle(0.5, -1.0, 1.0, style="red"), ]) SmithAxis(PGFPlots.SmithData([0+0im, 0.5+0.5im, 1.0+0.5im, 1.0+1.0im], style="thick, blue")) TernaryAxis( Plots.Linear3([0.1,0.4],[0.3,0.2],[0.6,0.4],style="solid, blue, thick"), style="ternary limits relative=false", xlabel=L"b_1", ylabel=L"b_2", zlabel=L"b_3" ) define_color("myrgbcolor1", [1,0.2,0.3]) Plots.Linear(x, y, style="myrgbcolor1") define_color("mycmykcolor1", [1,0.2,0.3,0]) Plots.Linear(x, y, style="mycmykcolor1") define_color("myRGBcolor", [82,227,246]) Plots.Linear(x, y, style="myRGBcolor") define_color("mylightgray", 0.9) Plots.Linear(x, y, style="mylightgray") define_color("myhtmlcolor", 0xff7f00) Plots.Linear(x, y, style="myhtmlcolor") define_color("mycolor", HSV(300, 0.2, 0.9)) Plots.Linear(x, y, style="mycolor, very thick") using DataFrames df = DataFrame(x=[1,2,3], y=[2,4,1], z=[0.0,0.5,1.0]) df_big = DataFrame(x=randn(1000), y=randn(1000)) df_quiver = DataFrame(x=[0,0,1,1], y=[0,1,0,1], u=[0.25,0.25,-0.25,-0.25], v=[0.25,-0.25,0.25,-0.25]) g = GroupPlot(3, 3, groupStyle = "horizontal sep = 1.75cm, vertical sep = 1.5cm") push!(g, Axis(Plots.Linear(df), title="Linear")) push!(g, Axis(Plots.Linear(df, x=:y, y=:z, style="red", mark="none"), title="Linear with Options")) push!(g, Axis(Plots.Linear3(df), title="Linear3")) push!(g, Axis(Plots.Scatter(df), title="Scatter")) push!(g, Axis(Plots.Histogram(df_big), title="Histogram")) push!(g, Axis(Plots.Quiver(df_quiver), title="Quiver")) push!(g, Axis(Plots.Histogram2(df_big), title="Histogram2 - Image")) push!(g, Axis(Plots.Histogram2(df_big, Float64[-3,-1,1,3], Float64[-3,-2,-1,0,1,2,3], style="colormap/blackwhite"), enlargelimits=0, title="Histogram2 = Patch2D")) g df = DataFrame(position=[0.0,0.5,1.5,4.0], time=[0.0,1.0,2.0,3.0]) Axis(Plots.Linear(df, x=:time, y=:position), xlabel="time [s]", ylabel="position [m]") Axis([ Plots.Linear(x, y, style="mycolor, very thick"), Plots.Command("\\legend{Test}") ]) pushPGFPlotsPreamble("\\usepackage{xfrac}") Plots.Linear(x, y, legendentry = L"\sfrac{1}{x}") popPGFPlotsPreamble() Plots.Linear(x, y, legendentry = "Test") pushPGFPlotsPreamble("\\usepackage{amsmath}") Axis(Plots.Linear([1,2], [1,2]), xlabel=L"x_\text{awesome}", ylabel="\$\\text{mathOperation}(x)\$") p = Plots.Histogram(rand(10)) save("myfile.tex", p) save("myfile.pdf", p) save("myfile.svg", p) p = Plots.Histogram(rand(10)) save("myfile.tex", p, include_preamble=false)