Open skanskan opened 7 years ago
I could probably add a few more examples, especially simple ones.
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?
Not a bad idea. I might try to look at this.
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.
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).
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).
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)
@skanskan: Is the above example simple enough? I ask because I could add it to the sample directory if you find it useful.
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.
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, ...
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)
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))
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)
What advantage has Easyplot over Plots.jl+inspectdr() ?
EasyData
. The format is not yet future proof, but unlike the current solution for Plots.jl, it has a definite format.(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}
.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.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.
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
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.