diff --git a/Project.toml b/Project.toml index 6c45ea1..441fa6d 100644 --- a/Project.toml +++ b/Project.toml @@ -16,14 +16,15 @@ ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" IndirectArrays = "9b13fd28-a010-5f03-acff-a1bbcff69959" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +Requires = "ae029012-a4dd-5104-9daa-d747884805df" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" TikzPictures = "37f6aa50-8035-52d0-81c2-5a1d08754b2d" [compat] -Contour = "0.5" ColorBrewer = "0.4" -Colors = "0.12" ColorSchemes = "3.9" +Colors = "0.12" +Contour = "0.5" DataFrames = "0.21" Discretizers = "3.2" ImageMagick = "0.7.3, 1" diff --git a/src/PGFPlots.jl b/src/PGFPlots.jl index 313a63c..f94da2a 100644 --- a/src/PGFPlots.jl +++ b/src/PGFPlots.jl @@ -8,10 +8,15 @@ export pushPGFPlots, popPGFPlots import Colors: RGB import Contour: contours, levels +using Requires using Discretizers -using DataFrames using Printf +# load dynamic dependencies +function __init__() + @require DataFrames="a93c6f00-e57d-5684-b7b6-d8193f3e46c0" include("dataframes.jl") +end + mutable struct ErrorBars data::AbstractMatrix{Real} style @@ -42,14 +47,6 @@ end include("colormaps.jl") include("plots.jl") -Plots.Linear(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = Plots.Linear(df[!,x], df[!,y]; kwargs...) -Plots.Linear3(df::DataFrame; x::Symbol=:x, y::Symbol=:y, z::Symbol=:z, kwargs...) = Plots.Linear3(df[!,x], df[!,y], df[!,z]; kwargs...) -Plots.Histogram(df::DataFrame; x::Symbol=:x, kwargs...) = Plots.Histogram(df[!,x]; kwargs...) -Plots.Scatter(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = Plots.Scatter(df[!,x], df[!,y]; kwargs...) -Plots.Quiver(df::DataFrame; x::Symbol=:x, y::Symbol=:y, u::Symbol=:u, v::Symbol=:v, kwargs...) = Plots.Quiver(convert(Vector, df[!,x]), convert(Vector, df[!,y]), convert(Vector, df[!,u]), convert(Vector, df[!,v]); kwargs...) -Plots.Histogram2(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]); kwargs...) -Plots.Histogram2(df::DataFrame, edges_x::AbstractVector{C}, edges_y::AbstractVector{C}; x::Symbol=:x, y::Symbol=:y, kwargs...) where {C<:Real} = Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]), edges_x, edges_y; kwargs...) - import TikzPictures: TikzPicture, PDF, TEX, TIKZ, SVG, save, LaTeXString, @L_str, @L_mstr _pgfplotsoptions = Any[""] diff --git a/src/dataframes.jl b/src/dataframes.jl new file mode 100644 index 0000000..f301d48 --- /dev/null +++ b/src/dataframes.jl @@ -0,0 +1,22 @@ +using DataFrames + +Plots.Linear(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = + Plots.Linear(df[!,x], df[!,y]; kwargs...) + +Plots.Linear3(df::DataFrame; x::Symbol=:x, y::Symbol=:y, z::Symbol=:z, kwargs...) = + Plots.Linear3(df[!,x], df[!,y], df[!,z]; kwargs...) + +Plots.Histogram(df::DataFrame; x::Symbol=:x, kwargs...) = + Plots.Histogram(df[!,x]; kwargs...) + +Plots.Scatter(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = + Plots.Scatter(df[!,x], df[!,y]; kwargs...) + +Plots.Quiver(df::DataFrame; x::Symbol=:x, y::Symbol=:y, u::Symbol=:u, v::Symbol=:v, kwargs...) = + Plots.Quiver(convert(Vector, df[!,x]), convert(Vector, df[!,y]), convert(Vector, df[!,u]), convert(Vector, df[!,v]); kwargs...) + +Plots.Histogram2(df::DataFrame; x::Symbol=:x, y::Symbol=:y, kwargs...) = + Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]); kwargs...) + +Plots.Histogram2(df::DataFrame, edges_x::AbstractVector{C}, edges_y::AbstractVector{C}; x::Symbol=:x, y::Symbol=:y, kwargs...) where {C<:Real} = + Plots.Histogram2(convert(Vector, df[!,x]), convert(Vector, df[!,y]), edges_x, edges_y; kwargs...)