-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rework coordinates. This is a step towards fixing #44, and is in accordance with the principles laid out there, but not the exact syntax proposed there since it was found to be impractical. Also fixes #11. 1. Introduce the `Coordinate` type for individual coordinates. Validate arguments and fail early. 2. Introduce `EmptyLine` for jumps/scanlines. This addresses #11. 3. Rewrite `Coordinates` to contain the above. (`<: OptionType` was removed, because it has no options). 4. Convenience constructors for creating coordinates from vectors, matrices, iterable objects, with or without error bars. Docstrings for the API. 5. Add examples of all the new syntax to the gallery (some of this should be moved to the documentation eventually, that will come later after other changes). 6. 2D histograms now work (example will be added later, when `Table` are redesigned similarly). * Fixed missing packages in REQUIRE. * small formatting changes
- Loading branch information
1 parent
2675941
commit c4d07af
Showing
9 changed files
with
386 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
julia 0.6 | ||
ArgCheck | ||
MacroTools | ||
Compat | ||
DataStructures | ||
DocStringExtensions | ||
Parameters | ||
Requires | ||
Crayons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Coordinates | ||
|
||
```jl | ||
import PGFPlotsX | ||
const pgf = PGFPlotsX | ||
using LaTeXStrings | ||
``` | ||
|
||
```@setup pgf | ||
import PGFPlotsX | ||
const pgf = PGFPlotsX | ||
using LaTeXStrings | ||
savefigs = (figname, obj) -> begin | ||
pgf.save(figname * ".pdf", obj) | ||
run(`pdf2svg $(figname * ".pdf") $(figname * ".svg")`) | ||
pgf.save(figname * ".tex", obj); | ||
return nothing | ||
end | ||
``` | ||
|
||
Use `Coordinates` to construct the `pgfplots` construct `coordinates`. Various constructors are available. | ||
|
||
For basic usage, consider `AbstractVectors` and iterables. Notice how non-finite values are skipped. You can also use `()` or `nothing` for jumps in functions. | ||
|
||
```@example pgf | ||
x = linspace(-1, 1, 51) # so that it contains 1/0 | ||
pgf.@pgf pgf.Axis( | ||
{ | ||
xmajorgrids, | ||
ymajorgrids, | ||
}, | ||
pgf.Plot( | ||
{ | ||
no_marks, | ||
}, | ||
pgf.Coordinates(x, 1 ./ x) | ||
) | ||
) | ||
savefigs("coordinates-simple", ans) # hide | ||
``` | ||
|
||
[\[.pdf\]](coordinates-simple.pdf), [\[generated .tex\]](coordinates-simple.tex) | ||
|
||
![](coordinates-simple.svg) | ||
|
||
Use `xerror`, `xerrorplus`, `xerrorminus`, `yerror` etc for error bars. | ||
```@example pgf | ||
x = linspace(0, 2π, 20) | ||
pgf.@pgf pgf.Plot( | ||
{ | ||
"no marks", | ||
"error bars/y dir=both", | ||
"error bars/y explicit", | ||
}, | ||
pgf.Coordinates(x, sin.(x); yerror = 0.2*cos.(x)) | ||
) | ||
savefigs("coordinates-errorbars", ans) # hide | ||
``` | ||
|
||
[\[.pdf\]](coordinates-errorbars.pdf), [\[generated .tex\]](coordinates-errorbars.tex) | ||
|
||
![](coordinates-errorbars.svg) | ||
|
||
Use three vectors to construct 3D coordinates. | ||
|
||
```@example pgf | ||
t = linspace(0, 6*π, 100) | ||
pgf.@pgf pgf.Plot3( | ||
{ | ||
no_marks, | ||
}, | ||
pgf.Coordinates(t .* sin.(t), t .* cos.(t), .-t) | ||
) | ||
savefigs("coordinates-3d", ans) # hide | ||
``` | ||
|
||
[\[.pdf\]](coordinates-3d.pdf), [\[generated .tex\]](coordinates-3d.tex) | ||
|
||
![](coordinates-3d.svg) | ||
|
||
A convenience constructor is available for plotting a matrix of values calculated from edge vectors. | ||
|
||
```@example pgf | ||
x = linspace(-2, 2, 20) | ||
y = linspace(-0.5, 3, 25) | ||
f(x, y) = (1 - x)^2 + 100*(y - x^2)^2 | ||
pgf.@pgf pgf.Plot3( | ||
{ | ||
surf, | ||
}, | ||
pgf.Coordinates(x, y, f.(x, y')); | ||
incremental = false | ||
) | ||
savefigs("coordinates-3d-matrix", ans) # hide | ||
``` | ||
|
||
[\[.pdf\]](coordinates-3d-matrix.pdf), [\[generated .tex\]](coordinates-3d-matrix.tex) | ||
|
||
![](coordinates-3d-matrix.svg) | ||
|
||
```@example pgf | ||
x = linspace(-2, 2, 40) | ||
y = linspace(-0.5, 3, 50) | ||
pgf.@pgf pgf.Axis( | ||
{ | ||
view = (0, 90), | ||
colorbar, | ||
"colormap/jet", | ||
}, | ||
pgf.Plot3( | ||
{ | ||
surf, | ||
shader = "flat", | ||
}, | ||
pgf.Coordinates(x, y, @. √(f(x, y'))); | ||
incremental = false | ||
) | ||
) | ||
savefigs("coordinates-3d-matrix-heatmap", ans) # hide | ||
``` | ||
|
||
[\[.pdf\]](coordinates-3d-matrix-heatmap.pdf), [\[generated .tex\]](coordinates-3d-matrix-heatmap.tex) | ||
|
||
![](coordinates-3d-matrix-heatmap.svg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.