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
mid
Center symbol, italic only when length>1sub
Optional: subscript after themid
sup
Optional: supscript after themid
presub
Optional: subscript before themid
presup
Optional: supscript before themid
option
Optional: choose fromtext
andmathrm
(default)
PlotPlants.latex_unit
— Functionlatex_unit(id::String;
paren::Bool = true,
squared::Bool = false,
space::Bool = true,
unicode::Bool = false
)
Return the unit, given
id
Identifier of the unit (if not in libary, use id as unit)paren
Optional: if true, include parenthesissquared
Optional: if true, use[]
, otherwise, use()
space
Optional: if true, add a SPACE at the beginningunicode
Optional. If true, return unicode; otherwise, return upgreek string
The predefined units include
A
μmol CO₂ m⁻² s⁻¹E
mol H₂O m⁻² s⁻¹E_MMOL
mmol H₂O m⁻² s⁻¹G
mol 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
id
Identifier for the greek letter, e.g., "alpha"unicode
Optional. 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
id
ID of the figurencol
Number of columns in the figurenrow
Number of rows in the figureaxids
Given indicies of the subplots in the figurefigsize
Given canvas sizedpi
Given pixels per inch
PlotPlants.save_canvas!
— Functionsave_canvas!(fig::Figure, path::String, saving::Bool = false)
Save a canvas, given
fig
Canvas to savepath
Path to save the figuresaving
Optional. 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
figs
An array of figuresfps
Frame per secondfn
File name of the GIF to saveimgs
An 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
ax
Axis to plot onxy
Center of the ellipsewidth
Width of the ellipseheight
Height of the ellipseangle
Rotation angle of the ellipsecolor
Color of the ellipseedgecolor
Edgecolor of the ellipsefacecolor
Face color of the ellipsealpha
Transparency 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
ax
Axis to plot onxy
Center of the stomawidth
Width of the stomaheight
Height of the stomastoma
Stomatal pore width ratioangle
Rotation 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
axs
An array of axislabels
Optional: labels after the panel title, e.g.,(a) label
paren
Optional: if true, use format like(a)
capital
Optional: if true, use capital letters like(A)
dotsep
Optional: if true, add a dot after the label like(a).
fontsize
Optional: fontsize of the titleloc
Optional: location of the titleusetex
Optional: 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
axs
An array of axislabels
X-axis labelsfontsize
Optional: 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
axs
An array of axislabels
Y-axis labelsfontsize
Optional: 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
axs
An array of axisxlabels
X-axis labelsylabels
Y-axis labelsfontsize
Optional: 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
axs
Array of axisxlims
Array 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
axs
Array of axisylims
Array of Y-axis limits
PlotPlants.set_xylims!
— Functionset_xylims!(axs::Array, xlims::Array, ylims::Array)
Set the X-axis limits, given
axs
Array of axisxlims
Array of X-axis limitsylims
Array 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
axs
Array of axisxticks
Array 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
axs
Array of axisyticks
Array of Y-axis ticks
PlotPlants.set_xyticks!
— Functionset_xyticks!(axs::Array, xticks::Array, yticks::Array)
Set Y-axis ticks for a given
axs
Array of axisxticks
Array of X-axis ticksyticks
Array 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
axs
Array of axisxticklabs
Array 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
axs
Array of axisyticklabs
Array 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
axs
Array of axisxticklabs
Array of X-axis tick labelsyticklabs
Array 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
ax
Given axisxs
Array of xys
Array of ylinestyle
Optional. Line style for the regression curve ("-" by default)intercept
Optional: if true, fit the data with an interceptinterval
Optional: if true, plot the confidence interval of fitted ycolor
Color the fitted curvealpha
Transparency 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
df
DataFrame that useX
andY
to store valuesintercept
Whether 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
xs
Array of x, can be NaNys
Array of y, can be NaNintercept
Optional: if true use intercept in the fittingsorting
Optional: if true, sort the values
PlotPlants.LinearRegressionResult
— Typemutable struct LinearRegressionResult
Fields
lm::Any
Regression result
r2::Number
Adjusted R square
inter::Number
Intercept of fitting
slope::Number
Slope of fitting
inter_p::Number
P value of intercept
slope_p::Number
P value of slopes
inter_ci::Array
Confidence interval of intercept
slope_ci::Array
Confidence interval of slopes
df::DataFrames.DataFrame
Predictions 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
xs
Array of x, can be NaNys
Array of y, can be NaNslope
Slope to testintercept
Optional: 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
xs
Array of Xys
Array of Ynthread
Number 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
ax
Axis to plot onxs
Array of Xys
Array of Ycmap
Optional. Color map schememarkersize
Optional. Marker size dimension, scatter size is markersize^2dmax
Maximal density. Ifdmax
is not NaN, use dmax as maximum densitydf
A 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
ax
Axis to plot onxs
Array of Xys
Array of Ycmap
Optional. Color map schemelogbins
Optional. If true, use log(count) to color the binsgridsize
Number of bins on both directionsxlim
Limits of x axis. Used to make plot region equal among subplotsylim
Limits 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
xs
Array of xys
Array of ytitle
Axis titilefigsize
Canvas sizexlab
X axis labelylab
Y axis labelmarker
Marker stylelinestyle
Line stylelabel_fontsize
X 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
filename
Dataset file to previewlabel
Label of the data to preview, variable name in NC files, band name in TIFF filesformat
AbstractFormat
type file format
PlotPlants.AbstractFormat
— TypePlotPlants.FormatNC
— Typestruct FormatNC
PlotPlants.FormatTIFF
— Typestruct FormatTIFF