User Tools

Site Tools


plotgallery2d


snippet.juliaeval
[download only julia statements]
pkgchk( "julia" => v"1.0.2", "Plots" => v"0.21.0" )

2-D Plot Gallery

For more simple X-Y line plots, and for illustration of many 2-D plot attributes, please consult plotattributes.

X-Y Plot

snippet.juliaeval
[download only julia statements]
using Plots; x=1:0.1:10; Y=[sin.(x),cos.(x)];
plot( x, Y )
savefig( "plotting/base2d.png" );

Ribbon Plot (Standard Errors around Curve)

snippet.juliaeval
[download only julia statements]
using Plots
x = -10:10
y = x .^ 2
plot(x, y, ribbon=2.0.*abs.(x), fillalpha=0.2)
savefig( "plotting/ribbon.png" )

Scatter Plots

Scatter Plot of Sin/Cos Curves

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, seriesalpha=0.5, seriescolor=[:blue :red], seriestype=:scatter );
savefig( "plotting/seriesscatter.png" );
This Graph Compare to Base

Scatter Plot Showing Marker Attributes

snippet.juliaeval
[download only julia statements]
using Plots
scatter( x[1:10], Y[1][1:10],
         markershape =:hexagon, markersize=20, markeralpha=0.6, markercolor=:green,
         markerstrokewidth=3, markerstrokealpha=0.2, markerstrokecolor=:black, markerstrokestyle=:dot);
savefig( "plotting/markers.png" );

Stick Plot

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, seriesalpha=0.5, seriescolor=[:blue :red], seriestype=:sticks );
savefig( "plotting/seriessticks.png" );
This Graph Compare to Base

Bar Plots

Two Bar Plots in One

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
bar( Y );
savefig("plotting/bar2.png")
This Graph Compare to Base

bar plots the first series and then plots the second series. Thus, the red series is above the blue series. If the alpha parameter is alpha=[1.0 0.7] this allows a visible “show-through” effect. If the alpha parameter is alpha=[0.7 1.0 ], it does not.

One Bar Plot

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
bar( Y[1] );
savefig("plotting/bar1.png")
This Graph Compare to Base

Changing Bar Width

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
bar( Y[1], bar_width=5 );
savefig( "plotting/bar_width.png" );
This Graph Compare to Base

Note how bars are plotted left to right, and thus left bars are obscured by right bars.

Changing To Horizontal Bars

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
bar( Y[1], orientation=:horizontal );
savefig( "plotting/orientation.png" );
This Graph Compare to Base

Histograms

You can use as seriestype either :barhist or :histogram . You could also use seriescolor.

One Histogram

snippet.juliaeval
[download only julia statements]
using Plots
using Distributions, StatsBase; n=1000; rn= quantile.( Normal(0.0,1.0), [1:n;]/(n+1));  ## see Random Variables
histogram( rn.^2, legend=false );	# a chi-squared
savefig( "plotting/histogram1.png" );

In real use, rn should be randomly shuffled. For a histogram, this does not matter

Two Histograms

snippet.juliaeval
[download only julia statements]
using Plots
using Distributions, StatsBase; n=1000; rn= quantile.( Normal(0.0,1.0), [1:n;]/(n+1) );  ## see Random Variables
histogram( [ rn.^2, rn ], alpha=0.5, label=["Normal Squared", "Plain Normal"] );
savefig( "plotting/histogram2.png" );

(Bar) Histogram

snippet.juliaeval
[download only julia statements]
using Plots
using Distributions, StatsBase; n=1000; rn= quantile.( Normal(0.0,1.0), [1:n;]/(n+1) );  ## see Random Variables
plot( [ rn.-1.0, 2.0.*rn.+1.0 ], bins=20, alpha= 0.5, seriestype=:barhist, label=["N(0,1)", "N(1,2)" ] )
savefig( "plotting/seriesbarhist.png" );

Step Histogram (Histogram Without Color)

snippet.juliaeval
[download only julia statements]
using Plots
using Distributions, StatsBase; n=1000; rn= quantile.( Normal(0.0,1.0), [1:n;]/(n+1) );  ## see Random Variables
plot( [ rn.-1.0, 2.0.*rn.+1.0 ], bins=20, seriesalpha= 0.5, seriestype=:stephist, legend=false )
savefig( "plotting/seriesstephist.png" );

Changing Histogram Number of Bins

snippet.juliaeval
[download only julia statements]
using Plots
using Distributions, StatsBase; n=1000; rn= quantile.( Normal(0.0,1.0), [1:n;]/(n+1) );  ## see Random Variables
p1= histogram( rn, bins=10, title="10 bins", legend=false );
p2= histogram( rn, bins=100, title="100 bins", legend=false );
p3= histogram( rn, bins=1000, title="1,000 bins", legend=false )
p4= histogram( rn, bins=100000, title="100,000 bins", legend=false )
plot( p1, p2, p3, p4, layout=4, size=[1200,480] )
savefig( "plotting/bins.png" );

Histogram Frequencies Instead of Counts

snippet.juliaeval
[download only julia statements]
using Plots
using Distributions, StatsBase; n=1000; rn= quantile.( Normal(0.0,1.0), [1:n;]/(n+1) );  ## see Random Variables
histogram( rn, normalize=true, label="Proportion" );
savefig( "plotting/histnormalize.png" );

Histogram With Weights

snippet.juliaeval
[download only julia statements]
using Plots
x= 0 : 0.001 : 0.999
histogram( x, weights=abs.(x .-0.5), legend=false );
savefig( "plotting/weights.png" );

  • this has a lot more weight on 0.0 and 1.0 than on 0.5

Scatter Histogram

Scatter histograms are likely not very useful—they use dots instead of bars.

snippet.juliaeval
[download only julia statements]
using Plots
using Distributions, StatsBase; n=1000; rn= quantile.( Normal(0.0,1.0), [1:n;]/(n+1) );  ## see Random Variables
plot( [ rn.-1.0, 2.0.*rn.+1.0 ], bins=20, alpha= 0.5, seriestype=:scatterhist, label=["N(0,1)", "N(1,2)" ] )
savefig( "plotting/seriessscatterhist.png" );

Pie Chart

snippet.juliaeval
[download only julia statements]
using Plots
plot( [ "a", "B", "c", "D", "e", "F" ], Y[1][1:6], seriestype=:pie );
savefig( "plotting/seriespie.png" )

may also explode segments out and do autopct=“%1.1f%%”,

Ways to add Lines and Polygons

HLine (Horizontal Lines)

snippet.juliaeval
[download only julia statements]
using Plots;
plot( [1:20;].^2, seriescolor=[:blue :red], seriestype=:hline, legend=false  );
savefig( "plotting/serieshline.png" );

or use hline!(x,y) directly. FIXME — why are we not cycling through series colors?

VLine (Vertical Lines)

snippet.juliaeval
[download only julia statements]
using Plots;
plot( [1:20;].^2, seriescolor=[:blue :red], seriestype=:vline, legend=false  );
savefig( "plotting/seriesvline.png" );

Polygon Shapes

snippet.juliaeval
[download only julia statements]
using Plots;
plot( [ 1.0, 3.0, 5.0, 3.0 ], [ 20.0, 40.0, 20.0, 100.0 ], seriestype=:shape, xlim=[-5,5], legend=false  );
savefig( "plotting/shape.png" )

markerstrokestyle is not supported with GR

Shady Mountain Plot

snippet.juliaeval
[download only julia statements]
using Plots;
plot( 0:10:100, rand(11,4), lab="lines", w=3, palette=:grays, fill=0, alpha=0.6);
savefig("plotting/shadymountain.png")

Both Plot (Scatter and Lines)

snippet.juliaeval
[download only julia statements]
using Plots;
plot( Vector[rand(10),rand(20)] , color=[:black :orange] , line=(:dot,4) , marker=( [:hex :d],12,0.8,stroke(3,:gray) ) );
savefig("plotting/sampleboth.png")

One Scatterplot, One Lineplot, One Regression Line

snippet.juliaeval
[download only julia statements]
using Plots;
plot( rand(100) / 3, reg=true, fill=(0,:green) ); scatter!( rand(100), markersize=6, c=:orange );
savefig("plotting/samplescatterlinereg.png")

Multiple Annotations

snippet.juliaeval
[download only julia statements]
using Plots
x= 1:15; y= sqrt.(x); ann= [(x[i]+0.13,y[i]+0.13,string(i)) for i in 1:length(x)]; scatter( x, y, annotations=ann, legend=false);
savefig("plotting/samplemanyannots.png")

Backmatter

Unknown or Unillustrated Parameters

FIXME Please suggest graphs that should be added, ideally with code.

Unknown and/or Unillustrated Parameters

FIXME More Attributes to explain

plot( x, Y, primary=);savefig( “plotting/ primary.png” );

plot( x, Y, seriesannotations=);savefig( “plotting/ seriesannotations.png” );

plot( x, Y, subplot=);savefig( “plotting/ subplot.png” ); ## subplot to which series belongs to

Commonly Useful Packages on Julia Repository

Notes

References


WARNING Do not edit this page. It is autogenerated from plotgallery2d.jl with mkplotgallerytxt.pl. The plots themselves are generated by running the julia files themselves.

plotgallery2d.txt · Last modified: 2018/11/22 20:48 (external edit)