Skip to content

Commit

Permalink
Add a bunch of failing tests for Unitful plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
non-Jedi committed Mar 17, 2018
1 parent 0423c12 commit e4729b7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
RDatasets
Cairo
Fontconfig
Unitful
19 changes: 19 additions & 0 deletions test/testscripts/unitful_basic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Unitful, Gadfly, DataFrames

a = -9.81u"m/s^2"
t = (1:0.5:10)u"s"
v = a * t
v2 = v + 2u"m/s"
h = 0.5 * a * t.^2
df = DataFrame(time=t, velocity=v, position=h,
unitlesst=ustrip.(t), unitlessv=ustrip.(v), unitlessh=ustrip.(h),
position2=reverse(h))

# test basics of point/line plots with Unitful
gridstack(reshape([plot(df, x=:time, y=:velocity),
plot(df, x=:position, y=:time),
plot(df, x=:unitlesst, y=:velocity),
plot(df, x=:time, y=:unitlessh),
plot(df, x=:time, y=:position, Geom.line),
plot(df, layer(x=:time, y=:position, Geom.line),
layer(x=:time, y=:position2))], (3,2)))
15 changes: 15 additions & 0 deletions test/testscripts/unitful_color.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Unitful, Gadfly, DataFrames

a = -9.81u"m/s^2"
t = (1:0.5:10)u"s"
v = a * t
v2 = v + 2u"m/s"
h = 0.5 * a * t.^2
df = DataFrame(time=t, velocity=v, position=h,
unitlesst=ustrip.(t), unitlessv=ustrip.(v), unitlessh=ustrip.(h),
position2=reverse(h))

# Test that it's possible to categorize by Unitful quantities
vstack(plot(df, x=:time, y=:position, color=:velocity, Geom.point),
plot(df, x=:time, y=:velocity, color=:position, Geom.line),
plot(df, x=:time, y=:position, color=:unitlessv))
26 changes: 26 additions & 0 deletions test/testscripts/unitful_geoms.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Unitful, Gadfly, DataFrames

a = -9.81u"m/s^2"
t = (1:0.5:10)u"s"
v = a * t
v2 = v + 2u"m/s"
h = 0.5 * a * t.^2
df = DataFrame(time=t, velocity=v, position=h,
unitlesst=ustrip.(t), unitlessv=ustrip.(v), unitlessh=ustrip.(h),
position2=reverse(h))

# Test various geometries with Unitful
p1 = plot(df, x=:time, y=:velocity, Geom.bar)
p2 = plot(df, x=:time, y=:position, Geom.point,
intercept=[-80u"m"], slope=[10u"m/s"], Geom.abline)
p3 = plot(df, x=:time, y=:velocity, Geom.line,
yintercept=[-20u"m/s", -40u"m/s"], Geom.hline)
# Currently explicitly stated that it loess and lm require arrays of plain numbers
#p4 = plot(df, x=:time, y=:position, Geom.point,
# Geom.smooth(method=:loess, smoothing=0.2))
p4 = plot(df, x=:position, y=:velocity, Geom.path)
p5 = plot(df, x=:time, y=:position, Geom.step,
xintercept=[3u"s", 8u"s"], Geom.vline)
p6 = plot(df, layer(x=:time, y=:position, Geom.line),
layer(x=:time, y=:position2, Geom.bar))
gridstack(reshape([p1,p2,p3,p4,p5,p6], (2,3)))

0 comments on commit e4729b7

Please sign in to comment.