InspectDR.jl icon indicating copy to clipboard operation
InspectDR.jl copied to clipboard

Additional examples

Open skanskan opened this issue 7 years ago • 9 comments

Hello.

It would be great to have more examples, maybe simple ones such as scatter plots, histograms, etc. and see how they look in a pdf file. Trying to reproduce some of the examples provided in https://learnr.files.wordpress.com/2009/08/latbook.pdf or in Gadly examples in order to compare their syntax, looking and speed.

skanskan avatar May 21 '17 10:05 skanskan

I could probably add a few more examples, especially simple ones.

latbook.pdf

I probably don't have time to create something as elaborate as what is in latbook.pdf in the forseeable future. Maybe you have specific examples you would like to see?

Gadfly examples

Not a bad idea. I might try to look at this.

scatter plots

This should not be difficult. In InspectDR, scatter plot are just regular 2D plots with no line, and a "glyph" (or marker).

I will give you a small demo as soon as I get a chance.

Histogram

InspectDR does not natively support histograms - but it does if used as a backend to Plots.jl. InspectDR is mostly designed to address large datasets (GB range) - because most plotting packages are excruciatingly slow in these situations.

That said, InspectDR has facilities allowing Plots.jl to draw histograms through the "shape" mechanism (see below).

Plots.jl

The best way to compare InspectDR with other plotting packages is using the Plots.jl: https://github.com/JuliaPlots/Plots.jl

The Plots.jl module has better documentation than InspectDR. Also, many new users would probably prefer the API of Plots.jl. The downside of using InspectDR through Plots.jl is that the compile-time & time-to-first plot are observably longer at the moment.

I even included a few sample plots generated using Plots.jl: https://github.com/ma-laforge/FileRepo/blob/master/InspectDR/sampleplots_Plots/README.md

Note: Test 25 is a scatter plot (generated using the Plots.jl API, of course).

ma-laforge avatar May 21 '17 12:05 ma-laforge

Ok, here is an example for a simple scatter plot:

#Simple demo 1: Simple scatter plot
#-------------------------------------------------------------------------------
using InspectDR
using Colors

red = RGB24(1, 0, 0)
green = RGB24(0, 1, 0)
blue = RGB24(0, 0, 1)

#==Input
===============================================================================#

x = collect(0:10) #Must vectorize using collect - ranges not yet supported
y = rand(length(x))


#==Generate plot object
===============================================================================#
plot = InspectDR.Plot2D(:lin, :lin,
	title = "Sample Scatter Plot",
	xlabel = "X-Values",
	ylabels = ["Y-Values"]
)
plot.layout.legend.enabled = true
plot.layout.legend.width = 150 #Default: 100

#Set grid:
graph = plot.strips[1]
graph.grid = InspectDR.GridRect(vmajor=true, vminor=true, hmajor=true)

wfrm = add(plot, x, y, id="Random Sample")
	wfrm.line = line(width=3, style=:none) #No line on a scatter plot; width used for glyph
	wfrm.glyph = glyph(shape=:o, size=10, color=red, fillcolor=blue)


#==Render plot
===============================================================================#
#Show Gtk GUI
gplot = display(InspectDR.GtkDisplay(), plot)

#Don't need to show GUI if simple plot image is desired:
InspectDR.write_png("simpledemo1.png", plot)
#InspectDR.write_svg("simpledemo1.svg", plot)
#InspectDR.write_eps("simpledemo1.eps", plot)
#InspectDR.write_pdf("simpledemo1.pdf", plot)

ma-laforge avatar May 21 '17 18:05 ma-laforge

@skanskan: Is the above example simple enough? I ask because I could add it to the sample directory if you find it useful.

Comment

InspectDR was not really designed to have a simple one-liner interface. That was more the goal of Plots.jl. Alot of thought went into that module. I would rather just make use of it instead of re-inventing the wheel.

When I don't want to use Plots.jl

What I tend to do, is wrap some pre-defined "template" into a function similar to what I did for transientplot() - located in the following file: https://github.com/ma-laforge/InspectDR.jl/blob/master/src/templates.jl

In other words, you would define your own scatterplot function - which would result in a more succinct call, like the following:

scatterplot(x, y, "Plot Title", "X-Title", "Y-Title")

In your function, you could decide what to use as the default glyph/symbol size/color/etc, which grids are displayed, ...

ma-laforge avatar May 21 '17 18:05 ma-laforge

Then, What package or procedure would you suggest If I just wanted to use a "simple one-liner" to quickly plot a scatterplot with 100000 points? (without previously creating templates)

skanskan avatar May 22 '17 10:05 skanskan

Plots.jl solution

using Plots

inspectdr() #Select InspectDR backend

x = 0:100_000
y = rand(length(x))

#The one-liner command itself:
display(plot(x, y, seriestype=:scatter))

ma-laforge avatar May 22 '17 16:05 ma-laforge

Alternative: CData.jl / EasyPlot.jl

NOTE: Plots.jl is still in the process of migrating to Julia v0.6.

An alternative is to use my own simplified plotting interface (not quite as elaborate as Plots.jl): https://github.com/ma-laforge/EasyPlot.jl

It is part of the CData.jl suite (Installation instructions on readme page): https://github.com/ma-laforge/CData.jl

The CData/EasyPlot solution looks as follows

#Simple demo 1: Simple scatter plot
#-------------------------------------------------------------------------------
using EasyPlotInspect #Simpler interface
using EasyPlot #Exports symbols
using MDDatasets #Required data structures

#==Input
===============================================================================#
x = collect(0:100_000) #Must vectorize using collect - ranges not yet supported
y = rand(length(x))
rnddata = DataF1(x, y) #EasyPlot requires "DataF1" object to keep x & y together

#==Generate plot
===============================================================================#
plot = EasyPlot.new(title = "Sample Plot")
	subplot = add(plot, title = "Scatter Plot") #Could also add x/y scale & labels here
	wfrm = add(subplot, rnddata, id="Random Sample")
	set(wfrm, line(style=:none), glyph(shape=:o, color=:blue, size=2))
display(plot)

It is not quite as succinct as what you get with Plots.jl (previous post)

ma-laforge avatar May 22 '17 16:05 ma-laforge

What advantage has Easyplot over Plots.jl+inspectdr() ?

skanskan avatar May 22 '17 16:05 skanskan

Plots.jl + inspectdr():

  • Designed for interactive work (Quick one-liners + progressively adding to plots).
  • Uses a MVC-type model to achieve goal: must select a backend before sending plot commands
  • Will one day save plot info + plot data to a single HDF5 file (https://github.com/JuliaPlots/Plots.jl/pull/825). However, the current solution is somewhat of an "object dump" due to the complexity of Plots.jl (not really future proof).
  • Large community support.

EasyPlot/EasyPlotInspect:

  • Designed for script-type work - where one does not mind setting attributes (plot titles, glyph colors, etc) on separate lines of code.
  • Uses a pure object/struct model to achieve goal: The plot object is fully backend-agnostic, and one can hold off on selecting the backend until it is time to display/save the plot.
  • Already can save plot info + plot data to a single HDF5 file with the help of module EasyData. The format is not yet future proof, but unlike the current solution for Plots.jl, it has a definite format.
  • Shorter time-to-first plot than Plots.jl.
  • Deals with (x, y) data using the DataF1 structure: DataF1 allows one to do complex math on functions of 1 argument (y=f(x)) even if the sampled x-values don't necessarily match. For example, operations on DataF1 will properly interpolate data1 + data2 even if data1 is sampled for x={1,3,9}, and data2 is sampled for x={2, 7, 22}.
  • Also supports "parametric sweeps": Arrays/collections of experiments (DataF1 "vectors") that were obtained under different conditions (ex: supply voltage = {1V & 2V}, & temp = {-40C, 0C, & 120C}. Instead of looping across the different experiments, mathematical operations are automatically vectorized.
  • Currently, I am the only one maintaining this module.

I should also probably mention that the CData/EasyPlot solution relies on a collection of modules that are not registered in METADATA (somewhat Julia-curated).

Since I have not figured out the proper way to tag/version these modules for different Julia distributions, the solution as a whole is much more likely to be broken when I start updating packages/migrating to new versions of Julia.

Though this might not be a big deal in certain applications, I can easily see people finding it unacceptable for practical use. However, I might try to improve things if there were sufficient demand.

ma-laforge avatar May 23 '17 00:05 ma-laforge

I'm having some related problems with the plots. I'm opening a new question here https://discourse.julialang.org/t/strange-things-with-plots-inspectdr/4937

skanskan avatar Jul 18 '17 19:07 skanskan