diff --git a/docs/example_generation.jl b/docs/example_generation.jl index 1b4f6604..0454b0b7 100644 --- a/docs/example_generation.jl +++ b/docs/example_generation.jl @@ -48,7 +48,7 @@ const examples = PlotExample[ [:(heatmap(randn(10000),randn(10000); nbins=200))]), PlotExample("Lots of line types", "Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar) \nNote: some may not work with all backends", - [:(plot(rand(20,4); linetypes=[:line, :step, :sticks, :dots]))]), + [:(plot(rand(20,4); linetypes=[:line, :step, :sticks, :dots], labels=["line","step","sticks","dots"]))]), PlotExample("Bar", "x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints)", [:(bar(randn(1000)))]), @@ -114,7 +114,8 @@ function generate_markdown(pkgname::Symbol) end # run it! -map(generate_markdown, (:qwt, :gadfly, :unicodeplots)) +# map(generate_markdown, (:qwt, :gadfly)) +generate_markdown(:unicodeplots) # generate separately so it's easy to comment out end # module diff --git a/docs/unicodeplots_examples.md b/docs/unicodeplots_examples.md index 5d876930..728d69de 100644 --- a/docs/unicodeplots_examples.md +++ b/docs/unicodeplots_examples.md @@ -86,7 +86,7 @@ Options: (:line, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, Note: some may not work with all backends ```julia -plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots]) +plot(rand(20,4); linetypes=[:line,:step,:sticks,:dots],labels=["line","step","sticks","dots"]) ``` ![](../img/unicodeplots_example_10.png) @@ -111,3 +111,38 @@ histogram(randn(1000); nbins=50,fillto=20) ![](../img/unicodeplots_example_12.png) +### Subplots + + subplot and subplot! are distinct commands which create many plots and add series to them in a circular fashion. + You can define the layout with keyword params... either set the number of plots `n` (and optionally number of rows `nr` or + number of columns `nc`), or you can set the layout directly with `layout`. + + Note: Gadfly is not very friendly here, and although you can create a plot and save a PNG, I haven't been able to actually display it. + + +```julia +subplot(randn(100,5); layout=[1,1,3],linetypes=[:line,:hist,:dots,:step,:bar],nbins=10,legend=false) +``` + +![](../img/unicodeplots_example_13.png) + +### Adding to subplots + +Note here the automatic grid layout, as well as the order in which new series are added to the plots. + +```julia +subplot(randn(100,5); n=4) +``` + +![](../img/unicodeplots_example_14.png) + +### + + + +```julia +subplot!(randn(100,3)) +``` + +![](../img/unicodeplots_example_15.png) + diff --git a/img/unicodeplots_example_1.png b/img/unicodeplots_example_1.png index ebc43e7e..ccd6c821 100644 Binary files a/img/unicodeplots_example_1.png and b/img/unicodeplots_example_1.png differ diff --git a/img/unicodeplots_example_10.png b/img/unicodeplots_example_10.png index e4522839..b49db126 100644 Binary files a/img/unicodeplots_example_10.png and b/img/unicodeplots_example_10.png differ diff --git a/img/unicodeplots_example_11.png b/img/unicodeplots_example_11.png index da49fb28..1b1041f0 100644 Binary files a/img/unicodeplots_example_11.png and b/img/unicodeplots_example_11.png differ diff --git a/img/unicodeplots_example_12.png b/img/unicodeplots_example_12.png index de253adc..62388f33 100644 Binary files a/img/unicodeplots_example_12.png and b/img/unicodeplots_example_12.png differ diff --git a/img/unicodeplots_example_13.png b/img/unicodeplots_example_13.png new file mode 100644 index 00000000..f3dde105 Binary files /dev/null and b/img/unicodeplots_example_13.png differ diff --git a/img/unicodeplots_example_14.png b/img/unicodeplots_example_14.png new file mode 100644 index 00000000..156d75e2 Binary files /dev/null and b/img/unicodeplots_example_14.png differ diff --git a/img/unicodeplots_example_15.png b/img/unicodeplots_example_15.png new file mode 100644 index 00000000..fe28e60d Binary files /dev/null and b/img/unicodeplots_example_15.png differ diff --git a/img/unicodeplots_example_2.png b/img/unicodeplots_example_2.png index ad13964a..913271a5 100644 Binary files a/img/unicodeplots_example_2.png and b/img/unicodeplots_example_2.png differ diff --git a/img/unicodeplots_example_3.png b/img/unicodeplots_example_3.png index d4b6f20e..1ba5d5b4 100644 Binary files a/img/unicodeplots_example_3.png and b/img/unicodeplots_example_3.png differ diff --git a/img/unicodeplots_example_4.png b/img/unicodeplots_example_4.png index f1760a85..3fee4bf5 100644 Binary files a/img/unicodeplots_example_4.png and b/img/unicodeplots_example_4.png differ diff --git a/img/unicodeplots_example_5.png b/img/unicodeplots_example_5.png index f364d29e..a0600ca4 100644 Binary files a/img/unicodeplots_example_5.png and b/img/unicodeplots_example_5.png differ diff --git a/img/unicodeplots_example_6.png b/img/unicodeplots_example_6.png index 39fccfec..33b8664f 100644 Binary files a/img/unicodeplots_example_6.png and b/img/unicodeplots_example_6.png differ diff --git a/img/unicodeplots_example_7.png b/img/unicodeplots_example_7.png index b6aec2a6..e959a8e2 100644 Binary files a/img/unicodeplots_example_7.png and b/img/unicodeplots_example_7.png differ diff --git a/img/unicodeplots_example_8.png b/img/unicodeplots_example_8.png index 5ec8e4b1..f5a904d2 100644 Binary files a/img/unicodeplots_example_8.png and b/img/unicodeplots_example_8.png differ diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index dad0faa7..41164a33 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -114,27 +114,46 @@ end # ------------------------------- -function savepng(::UnicodePlotsPackage, plt::PlottingObject, fn::String, args...) # = error("currently unsupported") +function savepng(::UnicodePlotsPackage, plt::PlottingObject, fn::String, args...) + + # make some whitespace and show the plot + println("\n\n\n\n\n\n") display(plt) - try + + @osx_only begin + # BEGIN HACK + + # wait while the plot gets drawn + sleep(0.5) + + # use osx screen capture when my terminal is maximized and cursor starts at the bottom (I know, right?) + # TODO: compute size of plot to adjust these numbers (or maybe implement something good??) + run(`screencapture -R50,600,700,420 $fn`) + + # # some other attempts: # run(`screencapture -w $fn`) - using PyCall - @pyimport pyscreenshot as pss - # todo: grab screen to $fn + # using PyCall + # @pyimport pyscreenshot as pss + + # END HACK (phew) return end - error("Can only savepng on osx with UnicodePlots.") + + error("Can only savepng on osx with UnicodePlots (though even then I wouldn't do it)") end # ------------------------------- -# create the underlying object (each backend will do this differently) +# we don't do very much for subplots... just stack them vertically + function buildSubplotObject!(::UnicodePlotsPackage, subplt::Subplot) - error("UnicodePlots doesn't support subplots") + nothing end function Base.display(::UnicodePlotsPackage, subplt::Subplot) - error("UnicodePlots doesn't support subplots") + for plt in subplt.plts + display(UnicodePlotsPackage(), plt) + end end