PlotPlants
Set global font
The PyPlot package of Julia uses sans font by default, by my favorite font is serif type. Also, some fonts do not have normal greek letters in their library, like the Times only have italic greek letters. To change the default font to serif and use normal greek letters, the PlotPlants package provides a use_serif_tex function, which use LaTeX amsmath and upgreek packages. Also, sans-serif font and normal text render are also supported.
PlotPlants.use_sans — Functionuse_sans()Set default font to sans-serif
PlotPlants.use_sans_tex — Functionuse_sans_tex()Set default font to sans and use latex wrapper for texts
PlotPlants.use_sans_text — Functionuse_sans_text()Set default font to sans and use normal text wrapper for texts
PlotPlants.use_serif — Functionuse_serif()Set default font to serif
PlotPlants.use_serif_tex — Functionuse_serif_tex()Set default font to serif and use latex wrapper for texts
PlotPlants.use_serif_text — Functionuse_serif_text()Set default font to serif and use normal text wrapper for texts
Symbols and units
To facilitate the use of LaTeX packages, functions latex_symbol and latex_unit are provided to rapidly generate equation symbols and units. By default,
- if the number of letters is one, the letter will be set to italic, otherwise, the letters will be normal (not italic);
- if the letter is greek, the letter will be normal;
- all sub- and super-scripts are normal;
PlotPlants.latex_symbol — Functionlatex_symbol(
mid::String;
sub::String = "",
sup::String = "",
presub::String = "",
presup::String = "",
option::String = "mathrm"
)Return the latex symbol string, given
midCenter symbol, italic only when length>1subOptional: subscript after themidsupOptional: supscript after themidpresubOptional: subscript before themidpresupOptional: supscript before themidoptionOptional: choose fromtextandmathrm(default)
PlotPlants.latex_unit — Functionlatex_unit(id::String;
paren::Bool = true,
squared::Bool = false,
space::Bool = true,
unicode::Bool = false
)Return the unit, given
idIdentifier of the unit (if not in libary, use id as unit)parenOptional: if true, include parenthesissquaredOptional: if true, use[], otherwise, use()spaceOptional: if true, add a SPACE at the beginningunicodeOptional. If true, return unicode; otherwise, return upgreek string
The predefined units include
Aμmol CO₂ m⁻² s⁻¹Emol H₂O m⁻² s⁻¹E_MMOLmmol H₂O m⁻² s⁻¹Gmol m⁻² s⁻¹PARμmol m⁻² s⁻¹T°CWUEμmol mol⁻¹
PlotPlants.parse_symbol — Functionparse_symbol(letter::String, unicode::Bool=false)Return the unicode or latex string, given
idIdentifier for the greek letter, e.g., "alpha"unicodeOptional. If true, return unicode; otherwise, return upgreek string
PlotPlants.subscript — Functionsubscript(ss::Number; option="mathrm", standalone=true)
subscript(ss::String; option="mathrm", standalone=true)Return a string of subscript, given
PlotPlants.superscript — Functionsuperscript(ss::Number; option="mathrm", standalone=true)
superscript(ss::String; option="mathrm", standalone=true)Return a string of superscript, given
Create and save canvas
An customized funtion create_canvas is provided to genrate figure and an array of axis from a few keywords. For example,
create_canvas(fig_id)returns a figure with one axis;create_canvas(fig_id, nrow=2, ncol=2)returns a figure will four subplots;create_canvas(fig_id, nrow=2, ncol=2, axs=[1,2,4])returns a figure with three subplot (the left bottom panel is empty);
PlotPlants.create_canvas — Functioncreate_canvas(
id::Union{Int,String};
ncol::Int = 1,
nrow::Int = 1,
axids::Array{Int,1} = Int[],
figsize::Tuple{Number,Number} = (0.5+ncol*3, 0.5+nrow*3),
dpi::Number = 100
)Create a canvas, given
idID of the figurencolNumber of columns in the figurenrowNumber of rows in the figureaxidsGiven indicies of the subplots in the figurefigsizeGiven canvas sizedpiGiven pixels per inch
PlotPlants.save_canvas! — Functionsave_canvas!(fig::Figure, path::String, saving::Bool = false)Save a canvas, given
figCanvas to savepathPath to save the figuresavingOptional. If true, save the figure
PlotPlants.save_gif! — Functionsave_gif!(figs::Array, fps::Int, gif::String)
save_gif!(imgs::Array{Array,1}, fps::Int, fn::String)Save an array of figures as GIF, given
figsAn array of figuresfpsFrame per secondfnFile name of the GIF to saveimgsAn array of array (loaded figures)
Shapes
A few customized shapes can be added to the canvas very conveniently, for example, stoma and ellipse. These shortcut functions include
PlotPlants.plot_ellipse! — Functionplot_ellipse!(
ax::PyObject,
xy::Tuple{Number,Number};
width::Number = 10,
height::Number = 10,
angle::Number = 0,
color::String = "black",
edgecolor::String = color,
facecolor::String = color,
alpha::Number = 0.5
)Plot an ellipse on axis, given
axAxis to plot onxyCenter of the ellipsewidthWidth of the ellipseheightHeight of the ellipseangleRotation angle of the ellipsecolorColor of the ellipseedgecolorEdgecolor of the ellipsefacecolorFace color of the ellipsealphaTransparency of the ellipse
PlotPlants.plot_stoma! — Functionplot_stoma!(
ax::PyObject,
xy::Tuple{Number,Number};
width::Number = 10,
height::Number = 10,
stoma::Number = 0.2,
angle::Number = 0
)Plot a stoma on the axis, given
axAxis to plot onxyCenter of the stomawidthWidth of the stomaheightHeight of the stomastomaStomatal pore width ratioangleRotation angle of the stoma
Set titles, lims, ticks, and ticklabels
Function set_titles! will add panel titles like (a) to all the panels, and if labels options is given, the labels will be added after the letter (e.g., (a) label).
PlotPlants.set_titles! — Functionset_titles!(axs::Array;
labels::Array{String,1} = String[],
paren::Bool = true,
capital::Bool = false,
dotsep::Bool = false,
fontsize::Number = 16,
loc::String = "center",
usetex::Bool = true
)Set titles for the axes, given
axsAn array of axislabelsOptional: labels after the panel title, e.g.,(a) labelparenOptional: if true, use format like(a)capitalOptional: if true, use capital letters like(A)dotsepOptional: if true, add a dot after the label like(a).fontsizeOptional: fontsize of the titlelocOptional: location of the titleusetexOptional: use latex render
Similarly, the package provides shortcuts to set the X-axis and Y-axis labels, limits, ticks, and tick labels.
PlotPlants.set_xlabels! — Functionset_xlabels!(
axs::Array,
xlabels::Array{String,1};
fontsize::Number = 16
)
set_xlabels!(
axs::Array,
xlabels::String;
fontsize::Number = 16
)Set X-axis labels for the axes, given
axsAn array of axislabelsX-axis labelsfontsizeOptional: fontsize of the label
PlotPlants.set_ylabels! — Functionset_ylabels!(
axs::Array,
ylabels::Array{String,1};
fontsize::Number = 16
)
set_ylabels!(
axs::Array,
ylabels::String;
fontsize::Number = 16
)Set Y-axis labels for the axes, given
axsAn array of axislabelsY-axis labelsfontsizeOptional: fontsize of the label
PlotPlants.set_xylabels! — Functionset_xylabels!(
axs::Array,
xlabels::Union{Array{String,1},String},
ylabels::Union{Array{String,1},String};
fontsize::Number = 16
)Set X-axis and Y-axis labels for the axes, given
axsAn array of axisxlabelsX-axis labelsylabelsY-axis labelsfontsizeOptional: fontsize of the label
PlotPlants.set_xlims! — Functionset_xlims!(axs::Array, xlims::Array)
set_xlims!(axs::Array,
xlims::Union{Array{Int,1},Array{Float32,1},Array{Float64,1}}
)Set the X-axis limits, given
axsArray of axisxlimsArray of X-axis limits
PlotPlants.set_ylims! — Functionset_ylims!(axs::Array, ylims::Array)
set_ylims!(axs::Array,
ylims::Union{Array{Int,1},Array{Float32,1},Array{Float64,1}}
)Set the Y-axis limits, given
axsArray of axisylimsArray of Y-axis limits
PlotPlants.set_xylims! — Functionset_xylims!(axs::Array, xlims::Array, ylims::Array)Set the X-axis limits, given
axsArray of axisxlimsArray of X-axis limitsylimsArray of Y-axis limits
PlotPlants.set_xticks! — Functionset_xticks!(axs::Array, xticks::Array)
set_xticks!(axs::Array,
xticks::Union{Array{Int,1},Array{Float32,1},Array{Float64,1}}
)Set X-axis ticks for a given
axsArray of axisxticksArray of X-axis ticks
PlotPlants.set_yticks! — Functionset_yticks!(axs::Array, yticks::Array)
set_yticks!(axs::Array,
yticks::Union{Array{Int,1},Array{Float32,1},Array{Float64,1}}
)Set Y-axis ticks for a given
axsArray of axisyticksArray of Y-axis ticks
PlotPlants.set_xyticks! — Functionset_xyticks!(axs::Array, xticks::Array, yticks::Array)Set Y-axis ticks for a given
axsArray of axisxticksArray of X-axis ticksyticksArray of Y-axis ticks
PlotPlants.set_xticklabels! — Functionset_xticklabels!(axs::Array, xticklabs::Array)
set_xticklabels!(axs::Array, xticklabs::Array{String,1})Set X-axis ticks for a given
axsArray of axisxticklabsArray of X-axis tick labels
PlotPlants.set_yticklabels! — Functionset_yticklabels!(axs::Array, yticklabs::Array)
set_yticklabels!(axs::Array, yticklabs::Array{String,1})Set Y-axis ticks for a given
axsArray of axisyticklabsArray of Y-axis tick labels
PlotPlants.set_xyticklabels! — Functionset_xyticklabels!(axs::Array, xticklabs::Array, yticklabs::Array)Set X-axis and Y-axis ticks for a given
axsArray of axisxticklabsArray of X-axis tick labelsyticklabsArray of Y-axis tick labels
Add regression
To quickly plot the regression lines, users may use
PlotPlants.plot_line_regress! — Functionplot_line_regress!(
ax::PyObject,
xs::Array,
ys::Array;
linestyle::String = "-",
intercept::Bool = true,
interval::Bool = false,
color::String = "red",
alpha::Number = 0.3
)Plor linear regression and confidence interval on the axis, given
axGiven axisxsArray of xysArray of ylinestyleOptional. Line style for the regression curve ("-" by default)interceptOptional: if true, fit the data with an interceptintervalOptional: if true, plot the confidence interval of fitted ycolorColor the fitted curvealphaTransparency of the confidence interval (same color as curve)
The function will filter out the NaN from the given data, make linear regression using function line_regress, sort the results by the value of x from low to high, store the results in a LinearRegressionResult type struct, and plot the regression line on the given axis. Also, if interval is set to true, the function will also plot the confidence intervals of the predicted y.
PlotPlants.linear_df_xy — Functionlinear_df_xy(df::DataFrame, intercept::Bool)Linear fit the X and Y in a given DataFrame, given
dfDataFrame that useXandYto store valuesinterceptWhether using intercept when making the regression
PlotPlants.line_regress — Functionline_regress(
xs::Array,
ys::Array;
intercept::Bool = true,
sorting::Bool = true
)Make linear regression and return the fitted results, given
xsArray of x, can be NaNysArray of y, can be NaNinterceptOptional: if true use intercept in the fittingsortingOptional: if true, sort the values
PlotPlants.LinearRegressionResult — Typemutable struct LinearRegressionResultFields
lm::AnyRegression result
r2::NumberAdjusted R square
inter::NumberIntercept of fitting
slope::NumberSlope of fitting
inter_p::NumberP value of intercept
slope_p::NumberP value of slopes
inter_ci::ArrayConfidence interval of intercept
slope_ci::ArrayConfidence interval of slopes
df::DataFrames.DataFramePredictions DataFrame
Further, the PlotPlants module provides a quick tool to test whether the slope differs from a given value, see
PlotPlants.test_slope — Functiontest_slope(xs::Array,
ys::Array;
slope::Number = 0,
intercept::Bool = true
)Make linear regression and return the p value of whether the regression slope differs from the given slope, given
xsArray of x, can be NaNysArray of y, can be NaNslopeSlope to testinterceptOptional: if true use intercept in the fitting
Density plot
PlotPlants.calculate_density — Functioncalculate_density(xs::Array, ys::Array)
calculate_density(xs::Array, ys::Array, nthread::Int)Plot density plot on axis, given
xsArray of XysArray of YnthreadNumber of threads to run in parallel
PlotPlants.plot_density! — Functionplot_density!(
ax::PyObject,
xs::Array,
ys::Array;
cmap::String = "viridis",
markersize::Number = 8,
dmax::Number = NaN
)
plot_density!(
ax::PyObject,
df::DataFrame;
cmap::String = "viridis",
markersize::Number = 8,
dmax::Number = NaN
)Plot density plot on axis, given
axAxis to plot onxsArray of XysArray of YcmapOptional. Color map schememarkersizeOptional. Marker size dimension, scatter size is markersize^2dmaxMaximal density. Ifdmaxis not NaN, use dmax as maximum densitydfA dataframe with column names of ("X","Y","C")
PlotPlants.plot_hexbin! — Functionplot_hexbin!(
ax::PyObject,
xs::Array,
ys::Array;
cmap::String = "Greys",
logbins::Bool = false,
gridsize::Number = 25
)
plot_hexbin!(
ax::PyObject,
xs::Array,
ys::Array,
xlims::Array,
ylims::Array;
cmap::String = "Greys",
logbins::Bool = false,
gridsize::Number = 25
)Plot density plot on axis, given
axAxis to plot onxsArray of XysArray of YcmapOptional. Color map schemelogbinsOptional. If true, use log(count) to color the binsgridsizeNumber of bins on both directionsxlimLimits of x axis. Used to make plot region equal among subplotsylimLimits of y axis. Used to make plot region equal among subplots
Preview dataset
PlotPlants.preview_data — Functionpreview_data(
xs::Array,
ys::Array;
title = randstring(10),
figsize::Tuple{Number,Number} = (4,3),
xlab::String = "X label",
ylab::String = "Y label",
marker::String = "",
linestyle::String = "-",
label_fontsize::Int = 12
)Preview data, given
xsArray of xysArray of ytitleAxis titilefigsizeCanvas sizexlabX axis labelylabY axis labelmarkerMarker stylelinestyleLine stylelabel_fontsizeX and Y axes label font size
PlotPlants.preview_dataset! — Functionpreview_dataset!(ax::PyObject, filename::String, label)
preview_dataset!(
ax::PyObject,
filename::String,
label::String,
format::FormatNC
)Preview dataset, given
filenameDataset file to previewlabelLabel of the data to preview, variable name in NC files, band name in TIFF filesformatAbstractFormattype file format
PlotPlants.AbstractFormat — TypePlotPlants.FormatNC — Typestruct FormatNCPlotPlants.FormatTIFF — Typestruct FormatTIFF