User Tools

Site Tools


plotattributes


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

2-D Plot Gallery

WARNING Some of the attributes in the Plots package still have some bugs, but Plots is maturing quickly.

Basic Overall Introduction

Base Figure

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

Overall Font

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

Overall Plot Area Color

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, background_color=:lightgray, background_color_outside=:yellow,
        foreground_color=:blue, background_color_legend=:green );
savefig( "plotting/ground_color.png" );
This Graph Compare to Base

* Not Shown: background_color_inside and background_color_subplot, foreground_color_subplot,

Plot Title

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, plot_title="Plot Title" )
savefig( "plotting/plot_title.png" );
This Graph Compare to Base
snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, title="Plot Title" )
savefig( "plotting/title.png" );
This Graph Compare to Base
snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot(x, Y, title="MyTitle", title_location=:left, titlefontcolor=:blue, titlefontfamily=:Courier, titlefontsize=30 )
savefig( "plotting/titlemany.png" );
This Graph Compare to Base

The following title-related attributes are either not working or are mysteries to me:

  • plot( x, Y, titlefonthalign=); savefig( “plotting/ titlefonthalign.png” );
  • plot( x, Y, titlefontrotation=); savefig( “plotting/ titlefontrotation.png” ); ## bug
  • plot( x, Y, titlefontvalign=); savefig( “plotting/ titlefontvalign.png” );
  • plot( x, Y, foregroundcolortitle=);savefig( “plotting/ foregroundcolortitle.png” );

Margins

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
using Measures
plot(x,Y, margin=10mm )
savefig( "plotting/margins.png" );
This Graph Compare to Base
snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
using Measures
plot(x,Y, left_margin=-20pt, right_margin=20mm, top_margin=0.5inch )  ## note---on the left, we extend outside
savefig( "plotting/marginsvaried.png" );
This Graph Compare to Base

Series Line Styles

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, linealpha=0.5, linecolor=[:blue :green], linestyle=[ :solid :dot], linewidth=[5 2]  )
savefig( "plotting/linebluegreen.png" );
This Graph Compare to Base

WARNING Multiple Series' Attributes Must be Passed as Matrix, Not as Vector

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
pl= plot( x, Y, linecolor=[:black,:red], linewidth=[5,3]  );
pr= plot( x, Y, linecolor=[:black :red], linewidth=[5 3]  );
plot( pl, pr, layout=2 )
savefig( "plotting/rightwrong.png" );
This Graph Compare to Base

The left is probably not what you expected. The problem is that on each point, the linecolors cycle through their values. The arguments on the right are matrices (not vectors), because they are space separated.

Legend

Naming Series

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

Not Printing Legend

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

plot( x, Y, legendfontcolor=:blue); savefig( "plotting/legendfontcolor.png" ); fails with error about alpha

Legend Font Family / Rotation /Size

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, legendfontfamily=:Courier);
savefig( "plotting/legendfontfamily.png" );
This Graph Compare to Base
snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, legendfontrotation=45);   ## this is a bug
savefig( "plotting/legendfontrotation.png" );
This Graph Compare to Base
snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, legendfontsize=6);
savefig( "plotting/legendfontsize.png" );
This Graph Compare to Base

Legend Title

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

Legend Color

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

Adding Features

Text Annotations

snippet.juliaeval
[download only julia statements]
using Plots
plot( x, Y, annotations=[ (3,-0.5, "at 3 and -0.5"), (6,-1,"at 6 and -1") ] );
plot!(; annotations=[ (3,0.25, text("larger text",20)) ] );
savefig( "plotting/annotations.png" )

Regression Lines

snippet.juliaeval
[download only julia statements]
using Plots; x=0.0 : 0.05 : 1; Y= x.^2
scatter( x, Y, smooth=true );
savefig( "plotting/smoothregline.png" );  ## add a regression line

Error Bars

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.05 : 1; Y=[ x.^2, x.^4 ];
plot( x, Y, xerror=abs.(x ./ 10));
savefig( "plotting/xerror.png" );

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.05 : 1; Y=[ x.^2, x.^4 ];
plot( x, Y, yerror=[abs.(x./10) abs.(x./100)]);
savefig( "plotting/yerror.png" );

Filling of Areas

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot(x, Y, fillrange=0, fillalpha=0.5, fillcolor=[ :red :blue ]);  ## the fillrange of 0 means start from x=0 up to line
savefig( "plotting/fillarea1.png" );
This Graph Compare to Base
snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot(x, sqrt.(x), fillrange=x, fillalpha=0.5, fillcolor=[:red], legend=false)  ## from .(x) to sqrt.(x)
savefig( "plotting/fillarea2.png" );
This Graph Compare to Base

Arrows

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

Arrows are more useful in the context of quiver plots, illustrated in 3-D Gallery.

Plot Resolution and Size

DPI

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, dpi=72 );
savefig( "plotting/dpi72.png" );  ## default=100
This Graph Compare to Base
snippet.juliaeval
[download only julia statements]
using Plots;
x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, dpi=36 )
savefig( "plotting/dpi36.png" );
This Graph Compare to Base

Size (Pixel Resolution)

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10;  Y=[ sin.(x), cos.(x) ];
plot( x, Y, size=[1200,300] );		## note: a tuple (like size=(1200,300)) would also work
savefig( "plotting/size.png" );
This Graph Compare to Base

Aspect Ratios

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

Frames and Thickness

Thickness Scaling

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

Frame Styles

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10;
p1= plot( x, Y, framestyle=:axis );
p2= plot( x, Y, framestyle=:semi );
p3= plot( x, Y, framestyle=:none );
p4= plot( x, Y, framestyle=:grid );
plot( p1, p2, p3, p4, layout=4 )
savefig( "plotting/framestyle.png" );

Not Showing Axes (Plot Borders)

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

Plot Range (X and Y Axes Plot Limits)

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, xlim=[0.1,5], ylim=[-0.5,2.0] );
savefig( "plotting/lim.png" );  ## lims
This Graph Compare to Base

Axes

Axes to Log Scale

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, xscale=:log10 );
savefig( "plotting/scale-log10.png" );  # depending on the backend, could also be xaxis=:log2 :ln
This Graph Compare to Base

Flipping Axes

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ x.^2, sqrt.(x) ];
plot( plot( x, Y, yflip=true ), plot( x, Y, xflip=true ),  layout=2 )
savefig( "plotting/flip.png" );

Mirroring Axes

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

Axis Color

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

Axes Labels (Guides)

The native name for axis label in Julia is “guide”.

Axis Label Color

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

Axis Label Font

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, guide="Axes Values", guidefontfamily=font("Times") );
savefig( "plotting/guidefontfamily.png" )
This Graph Compare to Base

Axis Label Font Size

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

Major and Minor Grids

For better visibility, the next few plots switch to blue color and greater line width, too.

Major Grid Color and Line Width

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, grid=true, foreground_color_grid=:blue, gridlinewidth=2 );
savefig( "plotting/grid.png" );
This Graph Compare to Base

Major Grid Alpha

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, grid=true, gridalpha=0.5, foreground_color_grid=:blue, gridlinewidth=2 );
savefig( "plotting/gridalpha.png" );
This Graph Compare to Base

Major Grid Style

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

Minor Grid

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, foreground_color_grid=:blue, gridlinewidth=2, minorgrid=true, minorgridalpha= 1.0,
         foreground_color_minor_grid=:red, minorgridlinewidth=3 );
savefig( "plotting/minor_grid.png" );
This Graph Compare to Base

Tick Marks

No Axes Tickmarks

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

Axes Tickmarks at Specialized Locations

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
xloc= [3,5,7]; xlab= ["three", "five", "seven"];
plot( x, Y, xticks= (xloc,xlab) )
savefig( "plotting/tickscustom.png" );
This Graph Compare to Base

* if you want only one tick, you must use plot!( xticks= (3.0, ["three"]) ). If you do not place the “three” into an array, it is interpreted as a character array, and only the 't' is printed.

Moving Tickmarks inside the Graph

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, tick_direction=:in );
savefig( "plotting/tick_direction.png" );	# ticks move inside the graphs (ticklabels stay outside)
This Graph Compare to Base

Changing Tickmarks Color

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, foreground_color_text=:blue );
savefig( "plotting/foreground_color_text.png" );  ## claims to apply to tick labels
This Graph Compare to Base

Removing Minor Tickmarks

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

Tick Labels

Tick Label Color

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

Change Tick Label Font

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, tickfontfamily=font("Times") );
savefig( "plotting/tickfontfamily.png" );
This Graph Compare to Base
snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, tickfontsize=18 );
savefig( "plotting/tickfontsize.png" );
This Graph Compare to Base
snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, xtickfont=font(24, "Courier"), ytickfont=font(6, "Courier") );
savefig( "plotting/tickfont.png" );
This Graph Compare to Base

Rotate Tick Labels

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10; Y=[ sin.(x), cos.(x) ];
plot( x, Y, xrotation=45, yrotation=90 );
savefig( "plotting/rotation.png" );  # rotation of tick labels
This Graph Compare to Base

Axes Tick Labels to Scientific Notation

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

Layouts For Multiple Graphs

snippet.juliaeval
[download only julia statements]
using Plots; x=1 : 0.1 : 10;
p1= plot( x, x );
p2= plot( x, sin.(x) );
p3= plot( x, cos.(x) );
p4= plot( x, tan.(x) );
plot( p1, p2, p3, p4, layout=4 )
savefig( "plotting/layout.png" );

  • To change the size of the figures, use size=[800,400] on any one of them. The others will be scaled to be similar.
  • A size= parameter on the final plot does not scale up or down the internal figures, but leaves more or less space between the figures.

Not sure about the following parameters:

  • plot( x, Y, subplotindex=int);savefig( “plotting/subplotindex.png” ) allows specifying an index. not sure how to use
  • plot( x, Y, fontfamilysubplot=);savefig( “plotting/ fontfamilysubplot.png” );
  • plot( x, Y, link=);savefig( “plotting/ link.png” ); link axis across subplots

Backmatter

Unknown or Unillustrated Parameters

not illustrated

The following are plot parameters that have not been illustrated:

  • plot( x, Y, overwrite_figure=false ); savefig( “plotting/.png” ); ## start a new figure
  • plot( x, Y, display_type=:auto );savefig( “plotting/.png” ); # :auto, :gui, :inline
  • plot( x, Y, extra_kwargs ); savefig( “plotting/.png” ); # pass arguments to a backend.
  • plot( x, Y, htmloutputformat ); savefig( “plotting/.png” ); # could be svg or png for
  • plot( x, Y, inset_subplots ); savefig( “plotting/.png” ); # vector of bounding box
  • plot( x, Y, link=:y ); savefig( “plotting/.png” ); ## link the axes between subplots
  • plot( x, Y, pos ); savefig( “plotting/.png” ); ## unimplemented location of plot within window
  • plot( x, Y, show ); savefig( “plotting/.png” ); ## automatic redisplay
  • plot( x, Y, window_title ); savefig( “plotting/.png” );

unknown

questions

  • show to auto-plot zero-axis and change their color
  • plot( x, Y, xlabel=“x values”, ylabel=“y values”);

Commonly Useful Packages on Julia Repository

Notes

References


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

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