User Tools

Site Tools


plotgallery2d

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

plotgallery2d [2018/12/27 13:27] (current)
Line 1: Line 1:
 +
 +
 +~~TOC 1-3 wide~~
 +
 +---
 +
 +^  [[plotting|Plotting Introduction]] ​ ^  [[plotattributes|Plot Attributes]] ​ ^  [[plotgallery2d|2-D Gallery]] ​ ^  [[plotgallery3d|3-D Gallery]] ​ ^
 +
 +
 +---
 +
 +
 +```juliaeval
 +julia> pkgchk.( "​julia"​ => v"​1.0.3",​ "​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
 +
 +```juliaeval
 +
 +using Plots; x=1:0.1:10; Y=[sin.(x),​cos.(x)];​
 +plot( x, Y )
 +savefig( "​plotting/​base2d.png"​ );
 +
 +```
 +
 +{{base2d.png}}
 +
 +## Ribbon Plot (Standard Errors around Curve)
 +
 +```juliaeval
 +
 +using Plots
 +x = -10:10
 +y = x .^ 2
 +plot(x, y, ribbon=2.0.*abs.(x),​ fillalpha=0.2)
 +savefig( "​plotting/​ribbon.png"​ )
 +
 +```
 +
 +{{ribbon.png}}
 +
 +## Scatter Plots
 +
 +### Scatter Plot of Sin/Cos Curves
 +
 +```juliaeval
 +
 +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  ^
 +|  {{seriesscatter.png}} ​ |  {{base.png}} ​ |
 +
 +### Scatter Plot Showing Marker Attributes
 +
 +```juliaeval
 +
 +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"​ );
 +
 +```
 +
 +{{markers.png}}
 +
 +## Stick Plot
 +
 +```juliaeval
 +
 +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  ^
 +|  {{seriessticks.png}} ​ |  {{base.png}} ​ |
 +
 +## Bar Plots
 +
 +### Two Bar Plots in One
 +
 +```juliaeval
 +
 +using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
 +bar( Y );
 +savefig("​plotting/​bar2.png"​)
 +
 +```
 +
 +
 +^  This Graph  ^  Compare to Base  ^
 +|  {{bar2.png}} ​ |  {{base.png}} ​ |
 +
 +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
 +
 +```juliaeval
 +
 +using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
 +bar( Y[1] );
 +savefig("​plotting/​bar1.png"​)
 +
 +```
 +
 +
 +^  This Graph  ^  Compare to Base  ^
 +|  {{bar1.png}} ​ |  {{base.png}} ​ |
 +
 +### Changing Bar Width
 +
 +```juliaeval
 +
 +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  ^
 +|  {{bar_width.png}} ​ |  {{base.png}} ​ |
 +
 +Note how bars are plotted left to right, and thus left bars are obscured by right bars.
 +
 +### Changing To Horizontal Bars
 +
 +```juliaeval
 +
 +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  ^
 +|  {{orientation.png}} ​ |  {{base.png}} ​ |
 +
 +## Histograms
 +
 +You can use as seriestype either :barhist or :histogram .  You could also use seriescolor.
 +
 +### One Histogram
 +
 +```juliaeval
 +
 +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"​ );
 +
 +```
 +
 +{{histogram1.png}}
 +
 +In real use, rn should be randomly shuffled. ​ For a histogram, this does not matter
 +
 +### Two Histograms
 +
 +```juliaeval
 +
 +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"​ );
 +
 +```
 +
 +{{histogram2.png}}
 +
 +### (Bar) Histogram
 +
 +```juliaeval
 +
 +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"​ );
 +
 +```
 +
 +{{seriesbarhist.png}}
 +
 +### Step Histogram (Histogram Without Color)
 +
 +```juliaeval
 +
 +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"​ );
 +
 +```
 +
 +{{seriesstephist.png}}
 +
 +### Changing Histogram Number of Bins
 +
 +```juliaeval
 +
 +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"​ );
 +
 +```
 +
 +{{bins.png}}
 +
 +### Histogram Frequencies Instead of Counts
 +
 +```juliaeval
 +
 +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"​ );
 +
 +```
 +
 +{{histnormalize.png}}
 +
 +### Histogram With Weights
 +
 +```juliaeval
 +
 +using Plots
 +x= 0 : 0.001 : 0.999
 +histogram( x, weights=abs.(x .-0.5), legend=false );
 +savefig( "​plotting/​weights.png"​ );
 +
 +```
 +
 +{{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.
 +
 +```juliaeval
 +
 +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"​ );
 +
 +```
 +
 +{{seriessscatterhist.png}}
 +
 +## Pie Chart
 +
 +```juliaeval
 +
 +using Plots
 +plot( [ "​a",​ "​B",​ "​c",​ "​D",​ "​e",​ "​F"​ ], Y[1][1:6], seriestype=:​pie );
 +savefig( "​plotting/​seriespie.png"​ )
 +
 +```
 +
 +{{seriespie.png}}
 +
 +may also explode segments out and do autopct="​%1.1f%%",​
 +
 +## Ways to add Lines and Polygons
 +
 +### HLine (Horizontal Lines)
 +
 +```juliaeval
 +
 +using Plots;
 +plot( [1:20;].^2, seriescolor=[:​blue :red], seriestype=:​hline,​ legend=false ​ );
 +savefig( "​plotting/​serieshline.png"​ );
 +
 +```
 +
 +{{serieshline.png}}
 +
 +or use `hline!(x,​y)` directly. ​ FIXME --- why are we not cycling through series colors?
 +
 +### VLine (Vertical Lines)
 +
 +```juliaeval
 +
 +using Plots;
 +plot( [1:20;].^2, seriescolor=[:​blue :red], seriestype=:​vline,​ legend=false ​ );
 +savefig( "​plotting/​seriesvline.png"​ );
 +
 +```
 +
 +{{seriesvline.png}}
 +
 +### Polygon Shapes
 +
 +```juliaeval
 +
 +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"​ )
 +
 +```
 +
 +{{shape.png}}
 +
 +markerstrokestyle is not supported with GR
 +
 +## ## Gallery of Various Multi-Feature 2-D Plots
 +
 +### Shady Mountain Plot
 +
 +```juliaeval
 +
 +using Plots;
 +plot( 0:10:100, rand(11,4), lab="​lines",​ w=3, palette=:​grays,​ fill=0, alpha=0.6);
 +savefig("​plotting/​shadymountain.png"​)
 +
 +```
 +
 +{{shadymountain.png}}
 +
 +### Both Plot (Scatter and Lines)
 +
 +```juliaeval
 +
 +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"​)
 +
 +```
 +
 +{{sampleboth.png}}
 +
 +### One Scatterplot,​ One Lineplot, One Regression Line
 +
 +```juliaeval
 +
 +using Plots;
 +plot( rand(100) / 3, reg=true, fill=(0,:​green) ); scatter!( rand(100), markersize=6,​ c=:orange );
 +savefig("​plotting/​samplescatterlinereg.png"​)
 +
 +```
 +
 +{{samplescatterlinereg.png}}
 +
 +### Multiple Annotations
 +
 +```juliaeval
 +
 +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"​)
 +
 +```
 +
 +{{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, series_annotations=);​savefig( "​plotting/​ series_annotations.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/12/27 13:27 (external edit)