Compare commits

...

124 Commits

Author SHA1 Message Date
Michael Krabbe Borregaard 09a17ba783 up GR version 2018-09-07 22:40:56 +02:00
Michael Krabbe Borregaard 046b291c1f remove the then 2018-09-07 16:02:19 +02:00
Michael Krabbe Borregaard 187a19bfd1 Merge pull request #1731 from mkborregaard/missings
rudimentary missings support
2018-09-07 15:54:22 +02:00
Michael Krabbe Borregaard 91816e6715 rename handlemissingsinmatrix 2018-09-07 15:38:20 +02:00
Michael Krabbe Borregaard 13339125eb drop stray @show 2018-09-07 15:31:04 +02:00
Michael Krabbe Borregaard 3197db9fc1 Merge pull request #1726 from mkborregaard/master
Run Travis on 1.0
2018-09-07 15:26:40 +02:00
Michael Krabbe Borregaard 6e4aac1123 Run Travis on 1.0 2018-09-07 15:26:06 +02:00
Michael Krabbe Borregaard 94450a26e9 restore String 2018-09-07 15:16:10 +02:00
Michael Krabbe Borregaard f571596eda Matrix support 2018-09-07 15:04:53 +02:00
Michael Krabbe Borregaard 8b6ca96e0a rudimentary missings support 2018-09-07 14:42:14 +02:00
Michael Krabbe Borregaard 198de2607a Merge pull request #1703 from daschw/appveyor
try default appveyor.yml
2018-09-07 09:59:09 +02:00
Josef Heinen 7cd1c9e8c8 Merge pull request #1729 from jheinen/master
gr: use new DPI setting for SVG output
2018-09-07 09:58:52 +02:00
Josef Heinen 9aa201dcb3 gr: use new DPI setting for SVG output 2018-09-06 21:37:18 +02:00
Josef Heinen 25b09a7962 Merge remote-tracking branch 'upstream/master'
t push
2018-08-30 10:19:25 +02:00
Michael Krabbe Borregaard 80151ac1a3 Merge pull request #1711 from mkborregaard/master
fix plotly errors; fix #1707
2018-08-29 18:49:27 +02:00
Michael Krabbe Borregaard bad5668ff7 Merge pull request #1704 from mkborregaard/old_spy
Reinstate scatter-based spy implementation; fix #1682
2018-08-29 18:41:20 +02:00
Michael Krabbe Borregaard cad0f15aed fix plotly errors 2018-08-29 18:38:53 +02:00
Michael Krabbe Borregaard 9c42c30d8a Merge pull request #1710 from mkborregaard/master
Fix aliases bug
2018-08-29 10:39:58 +02:00
Michael Krabbe Borregaard c471d1e4c3 finalize d -> plotattributes 2018-08-29 09:56:59 +02:00
Michael Krabbe Borregaard 7ae4fae68c fix bug in aliases 2018-08-29 09:56:44 +02:00
Josef Heinen 2405d5151b Merge remote-tracking branch 'upstream/master'
t push
2018-08-29 07:42:46 +02:00
Michael Krabbe Borregaard 4f667291bd remove spurious warning 2018-08-28 21:39:02 +02:00
Michael Krabbe Borregaard 49ad3a51aa update news 2018-08-28 14:49:42 +02:00
Michael Krabbe Borregaard f2e98acc65 Merge pull request #1681 from mkborregaard/plotattributes
change all instances of `d` to `plotattributes.
2018-08-28 14:39:44 +02:00
Michael Krabbe Borregaard b68adde751 up recipesbase and julia dep versions 2018-08-28 14:38:53 +02:00
Michael Krabbe Borregaard 7220eca7a8 Clean up after rebase 2018-08-28 10:13:33 +02:00
Michael Krabbe Borregaard 10dd9b5120 fix errors 2018-08-28 10:10:13 +02:00
Michael Krabbe Borregaard 7590c133fd replace d -> plotattributes in the rest of the files 2018-08-28 10:10:13 +02:00
Michael Krabbe Borregaard 2873685517 Replace d -> plotattributes in most files 2018-08-28 10:10:13 +02:00
Michael Krabbe Borregaard 9887892a92 reinstate marker_z 2018-08-28 09:55:15 +02:00
Daniel Schwabeneder 6fa15751ae try default appveyor.yml 2018-08-27 19:38:57 +02:00
Josef Heinen 24e3fcbb6c Merge remote-tracking branch 'upstream/master'
t push
2018-08-27 08:33:21 +02:00
Michael Krabbe Borregaard 91f51778f1 Don't define invisible when two colors 2018-08-26 23:10:33 +02:00
Michael Krabbe Borregaard 5c2bf5d76c Don't color points 2018-08-26 23:10:33 +02:00
Michael Krabbe Borregaard c4233e2896 larger markers 2018-08-26 23:10:33 +02:00
Michael Krabbe Borregaard e0b7bdc1a5 Revert "Merge pull request #1155 from mkborregaard/newspy"
This reverts commit b71cfce105.
2018-08-26 23:10:33 +02:00
Michael Krabbe Borregaard 91ec39e141 Merge pull request #1696 from JeffFessler/patch-1
Add :match_dimensions to address #1694
2018-08-26 22:58:31 +02:00
Michael Krabbe Borregaard 602dbdf1d2 Merge pull request #1695 from JuliaPlots/pv/group
RFC WIP: sort x axis in group_as_matrix
2018-08-26 22:57:04 +02:00
Daniel Schwabeneder 3eabaf074a Merge pull request #1691 from daschw/performance
Performance improvements
2018-08-26 22:52:50 +02:00
Daniel Schwabeneder a81178121f implement pyplot 2018-08-26 22:41:40 +02:00
Daniel Schwabeneder e1a83aab1d implement plotly 2018-08-26 22:41:40 +02:00
Daniel Schwabeneder 84601bacdb gr implementation 2018-08-26 22:41:40 +02:00
Daniel Schwabeneder e991e2bf37 implement additional get_***color methods 2018-08-26 22:41:40 +02:00
Daniel Schwabeneder 9b6fc4bc6b Merge pull request #1667 from pfitzseb/sp/betterdisplay
WIP: Actually use PlotsDisplay()
2018-08-26 22:05:29 +02:00
Daniel Schwabeneder c9e832600c Merge pull request #1700 from daschw/pkg3
Fix tests
2018-08-26 22:04:02 +02:00
Daniel Schwabeneder 25190d945d Merge pull request #1689 from tkf/pkg3
Fix CI
2018-08-26 21:16:15 +02:00
Daniel Schwabeneder b2f2ffcfed fix tests 2018-08-26 21:11:23 +02:00
Jeff Fessler 00821c1ae3 Add :match_dimensions to address #1694
see also #273 and #196, for f(x,y) vs f(y,x), and transpose=true
2018-08-25 14:49:52 -04:00
Pietro Vertechi 937acbc218 sort x axis in group_as_matrix 2018-08-25 19:04:42 +01:00
Takafumi Arakaki e0f9313b8b Use import PlotReferenceImages 2018-08-25 07:16:42 -07:00
Takafumi Arakaki 6d0d8ea90a Use qualified name Statistics.mean 2018-08-25 07:16:42 -07:00
Takafumi Arakaki ebf32390ef Import Gtk in interactive session 2018-08-24 17:16:52 -07:00
Takafumi Arakaki eefea15069 Don't use Base.mean 2018-08-24 17:14:19 -07:00
Takafumi Arakaki 531dd43284 Add FileIO to test/REQUIRE 2018-08-24 17:14:19 -07:00
Takafumi Arakaki e483ce85dc Install unregistered packages in test/runtests.jl 2018-08-24 17:14:19 -07:00
Takafumi Arakaki 80da14c1fb Use pathof(PlotReferenceImages) instead of Pkg.dir 2018-08-24 17:14:19 -07:00
Takafumi Arakaki 374580a3d6 Import Pkg 2018-08-24 17:14:19 -07:00
Takafumi Arakaki 4a51e4e7fb Import Random 2018-08-24 17:14:19 -07:00
Josef Heinen ae969dad38 Merge remote-tracking branch 'upstream/master'
t push
2018-08-24 04:18:05 -04:00
Takafumi Arakaki 7fcd008f2f Fix appveyor.yml 2018-08-23 14:32:05 -07:00
Takafumi Arakaki def5be630a Use Pkg3 API in travis_commands.jl 2018-08-23 14:27:21 -07:00
Michael Krabbe Borregaard de3848ff53 Merge pull request #1688 from mkborregaard/add_undef
Add some undefs to Array constructors
2018-08-23 22:24:17 +02:00
Michael Krabbe Borregaard 8d4ab6bb94 Also fix broadcast on dict 2018-08-23 16:51:15 +02:00
Michael Krabbe Borregaard 28ac117d68 Add some undefs to Array constructors 2018-08-23 16:31:28 +02:00
Josef Heinen 065ff48b15 Merge remote-tracking branch 'upstream/master'
t push
2018-08-22 06:12:20 -04:00
Daniel Schwabeneder 69bdd6db83 Merge pull request #1643 from tkf/single-colorbar
Make sure only one colorbar is drawn with GR
2018-08-22 09:37:59 +02:00
Daniel Schwabeneder cd270dd407 Merge pull request #1657 from tkf/colorbar_title
Implement colorbar_title for GR
2018-08-22 09:34:03 +02:00
Daniel Schwabeneder b4944a6f81 Merge pull request #1664 from mortenpi/fix-pyplot-savefig
Fix savefig with latexstring for pyplot
2018-08-22 09:18:45 +02:00
Michael Krabbe Borregaard 4049bf20c2 Merge pull request #1686 from JuliaPlots/pv/nt
Fix NamedTuple integration
2018-08-21 23:40:24 +02:00
Michael Krabbe Borregaard 805ca0d378 Merge pull request #1678 from improbable22/remove-P2-P3
Remove P2 & P3 from export
2018-08-21 22:01:59 +02:00
Pietro Vertechi fcaae346a7 Fix NamedTuple integration 2018-08-21 18:17:47 +01:00
Michael Krabbe Borregaard 0684102511 Merge pull request #1674 from djsegal/djsegal/colorbar
Add way to give colorbar_title for pgfplots
2018-08-19 21:29:38 +02:00
Michael Krabbe Borregaard 6ca87f6d33 Merge pull request #1680 from JuliaPlots/mkb/doc_badge
Replace link to docs with docs badge
2018-08-19 15:54:10 +02:00
Michael Krabbe Borregaard 3c96831cdc fix_1 2018-08-19 15:53:36 +02:00
Michael Krabbe Borregaard b551f6714b Replace link to docs with docs badge 2018-08-19 15:49:05 +02:00
Sebastian c005cc211f Add example 2018-08-19 13:52:26 +02:00
Unknown 92b0d5c0be Add line_z and update arg_desc.jl 2018-08-19 13:52:26 +02:00
SebastianM-C 45dc9e5c0d Add 2D marker_z with Functions 2018-08-19 13:52:26 +02:00
djsegal 7c505949fc Add “colorbar_title” to pgfplots 2018-08-19 02:25:04 -04:00
improbable22 905accdb7d Remove P2 & P3 from export
As in #1675, important stuff!
2018-08-19 07:20:17 +02:00
Michael Krabbe Borregaard 30f3e3cf56 Merge pull request #1676 from mkborregaard/plotattr
make plotattr work again
2018-08-18 23:24:54 +02:00
Michael Krabbe Borregaard 71131fd00c make plotattr work again 2018-08-18 23:24:14 +02:00
Michael Krabbe Borregaard 60b8b0080c Merge pull request #1670 from mkborregaard/master
Address UInt round problem - see #1665
2018-08-17 20:58:01 +02:00
Michael Krabbe Borregaard b30ff9b41b Merge pull request #1671 from mkborregaard/getrgb_patch
Add vector function for rgb
2018-08-17 11:21:01 +02:00
Michael Krabbe Borregaard cf1a0e3c33 Add vector function for rgb 2018-08-17 11:19:57 +02:00
Michael Krabbe Borregaard e94fe13178 Merge pull request #1668 from anowacki/an/1665
Remove broadcasting of getSeriesRGBColor
2018-08-17 11:17:15 +02:00
Michael Krabbe Borregaard b2c4561a7d gr: round to UInt not Int
Fixes an error with 32-bit system compatibility
2018-08-17 10:50:05 +02:00
Andy Nowacki ef63c8d66e Remove broadcasting of getSeriesRGBColor
No longer broadcast over d[:seriescolor] when updating
series attributes.  This fixes #1665, where in Julia
v1.0 the PlotUtils ColorGradient type is assumed to
be iterable (JuliaLang/julia/#18618).
2018-08-16 15:28:36 +01:00
Sebastian Pfitzner 00be8a2237 make sure display order is correct if Plots is loaded before the REPL 2018-08-16 12:34:33 +02:00
Sebastian Pfitzner 6593e3cfe6 actually use __init__ 2018-08-16 12:23:23 +02:00
Sebastian Pfitzner ac73798b9d actually use PlotsDisplay()
instead of overloading display for REPLDisplay
2018-08-16 11:59:56 +02:00
Michael Krabbe Borregaard 1697b99bbc Merge pull request #1663 from mkborregaard/travis-0.7
update travis script; fix #1658
2018-08-16 11:21:00 +02:00
Josef Heinen 1e9467a221 Merge remote-tracking branch 'upstream/master'
t push
2018-08-16 10:48:48 +02:00
Takafumi Arakaki b56238089c Use TEXT_VALIGN_TOP 2018-08-15 21:24:20 -07:00
Morten Piibeleht 47d8aa871b Do not import latexstring into the global scope
It will not be visible to functions in Plots anyway. Instead, labelfunc
now explicitly specifies that it uses LaTeXStrings.latexstring.
2018-08-16 11:05:39 +12:00
Morten Piibeleht 87627b8320 Wrap latexstring use in an at-require
latexstring comes from the LaTeXStrings package, which is conditionally
loaded by pyplot().

Fix #1659.
2018-08-16 11:03:21 +12:00
Michael Krabbe Borregaard c419f87b64 update travis script; fix #1658 2018-08-15 23:20:18 +02:00
Michael Krabbe Borregaard 9ae22a1ad7 Merge pull request #1660 from CarloLucibello/glv
fix glvisualize require
2018-08-15 16:01:01 +02:00
CarloLucibello b4dfd35be6 fix glvisualize require 2018-08-15 09:30:52 -04:00
Josef Heinen 916654b3ec Merge remote-tracking branch 'upstream/master'
t push
2018-08-15 07:51:30 +02:00
Takafumi Arakaki 2acd088226 Implement colorbar_title for GR 2018-08-14 20:28:22 -07:00
Michael Krabbe Borregaard 2d217edc15 update news.md 2018-08-14 23:56:21 +02:00
Michael Krabbe Borregaard b55d13bc21 Merge pull request #1655 from roshanshariff/julia-1.0
Fix julia 0.7 deprecated syntax in Plotly backend.
2018-08-14 23:53:35 +02:00
Michael Krabbe Borregaard 1f9468e029 Merge pull request #1656 from mkborregaard/pyplot
Add more packages to PyPlot string
2018-08-14 23:53:03 +02:00
Roshan Shariff 593804096d Fix julia 0.7 deprecated syntax in Plotly backend. 2018-08-14 15:38:55 -06:00
Michael Krabbe Borregaard befb14682d Add more packages to PyPlot string 2018-08-14 23:28:18 +02:00
Michael Krabbe Borregaard 07a6700ab6 Merge pull request #1654 from ma-laforge/hdf5
Deal w/deprecation of Nullable.
2018-08-14 22:57:17 +02:00
MA Laforge 8131953e49 Deal w/deprecation of Nullable.
Also use new LinearIndices API.
2018-08-14 13:04:22 -07:00
Michael Krabbe Borregaard 7e360aa915 Merge pull request #1651 from mkborregaard/master
Update instances of `findfirst` to 1.0 syntax
2018-08-14 10:24:40 +02:00
Michael Krabbe Borregaard 0710fba638 Update instances of findfirst to 1.0 syntax 2018-08-14 10:24:10 +02:00
Josef Heinen ad1bcbb0ac Merge remote-tracking branch 'upstream/master'
t push
2018-08-14 10:13:06 +02:00
Michael Krabbe Borregaard afb7a17e5f Merge pull request #1650 from mkborregaard/master
1.0 updates to animations
2018-08-14 09:20:34 +02:00
Michael Krabbe Borregaard badf302756 Explicitly specify assignment to global 2018-08-14 09:19:32 +02:00
Michael Krabbe Borregaard 99941dde8f info --> @info 2018-08-14 09:13:27 +02:00
Michael Krabbe Borregaard e5c55b6962 Merge pull request #1647 from joshday/patch-1
import findnz from SparseArrays
2018-08-13 15:05:42 +02:00
Josh Day 7a7f4cb306 import findnz from SparseArrays 2018-08-13 08:58:38 -04:00
Josef Heinen c0ff8f80b1 t push
Merge remote-tracking branch 'upstream/master'
2018-08-13 11:41:59 +02:00
Michael Krabbe Borregaard d084e31065 Merge pull request #1644 from mkborregaard/master
Don't broadcast `plot_color`; fix #1641
2018-08-13 10:08:57 +02:00
Michael Krabbe Borregaard 12008ef1c6 Don't broadcast plot_color; fix #1641
On 1.0 you can no longer pass a singleton argument to broadcast without escaping with `Ref`. But - `plot_color` has `Vector` methods, so it should be fine to not broadcast here. The example from the PR that introduced the broadcast here still works on this PR https://github.com/JuliaPlots/Plots.jl/pull/1467#issue-178940271
2018-08-13 10:07:03 +02:00
Takafumi Arakaki 23ec52c6b4 Make sure only one colorbar is drawn with GR
closes #1642
2018-08-13 00:06:12 -07:00
Josef Heinen 5485740291 Merge remote-tracking branch 'upstream/master'
t push
2018-08-12 19:38:17 +02:00
Josef Heinen 5565680b53 t push
Merge remote-tracking branch 'upstream/master'
2018-08-10 19:57:25 +01:00
Josef Heinen 15ddc5f06c Merge remote-tracking branch 'upstream/master' 2018-08-01 13:18:22 +02:00
Josef Heinen 3559b539e3 gr: use correct text bounding box for mathtex 2018-07-31 16:06:37 +02:00
45 changed files with 1500 additions and 1442 deletions
+1
View File
@@ -5,3 +5,4 @@
examples/.ipynb_checkpoints/*
examples/meetup/.ipynb_checkpoints/*
deps/plotly-latest.min.js
deps/build.log
+5 -5
View File
@@ -4,7 +4,7 @@ os:
- linux
# - osx
julia:
# - 0.7
# - 1.0
- nightly
# matrix:
# allow_failures:
@@ -43,10 +43,10 @@ before_install:
notifications:
email: true
# uncomment the following lines to override the default test script
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'using Pkg; Pkg.add(pwd()); Pkg.build("Plots")'
- julia test/travis_commands.jl
# script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'import Pkg; Pkg.add(Pkg.PackageSpec(path=pwd())); Pkg.build("Plots")'
# - julia test/travis_commands.jl
# - julia -e 'Pkg.clone("ImageMagick"); Pkg.build("ImageMagick")'
# - julia -e 'Pkg.clone("GR"); Pkg.build("GR")'
# # - julia -e 'Pkg.clone("https://github.com/tbreloff/ImageMagick.jl.git"); Pkg.checkout("ImageMagick","tb_write"); Pkg.build("ImageMagick")'
+27
View File
@@ -12,6 +12,33 @@
## (current master)
- All new development should target Julia 1.x!
## 0.20.0
Many updates, min julia 1.0
- change display type to use PlotsDisplay (fixes Juno integration)
- change all internal uses of `d` to `plotattributes` (no user change)
- change spy implementation to use `scatter` not `heatmap`
- sort x axes when passing a vector of strings as x
- improve performance of marker_z
- update CI to 1.0
- minor depwarn ifixes
- only draw one colorbar with GR
- add colorbar_title to GR and pgfplots
- fix savefig with latexstrings for PyPlot
- fix NamedTuple integration
- don't export `P2` and `P3`
- make it possible to use 2-argument function as argument to marker_z
- make `plotattr` work again
## 0.19.3
- fix some julia 0.7 deprecations
- fix 32-bit OS functionality
## 0.19.2
- several small fixes for 1.0 compatibility
## 0.19.1
- don't broadcast plot_color
## 0.19.0
- Refactor conditional loading to use Requires
- Many fixes for 1.0 compatibility
+1 -2
View File
@@ -3,6 +3,7 @@
[![Build Status](https://travis-ci.org/JuliaPlots/Plots.jl.svg?branch=master)](https://travis-ci.org/JuliaPlots/Plots.jl)
[![Build status](https://ci.appveyor.com/api/projects/status/github/juliaplots/plots.jl?branch=master&svg=true)](https://ci.appveyor.com/project/mkborregaard/plots-jl)
[![Join the chat at https://gitter.im/tbreloff/Plots.jl](https://badges.gitter.im/tbreloff/Plots.jl.svg)](https://gitter.im/tbreloff/Plots.jl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
<a href="http://docs.juliaplots.org/latest/" target="_blank"><img src="https://img.shields.io/badge/docs-latest-blue.svg" alt="Latest documentation"></a>
<!-- [![Plots](http://pkg.julialang.org/badges/Plots_0.3.svg)](http://pkg.julialang.org/?pkg=Plots&ver=0.3) -->
<!-- [![Plots](http://pkg.julialang.org/badges/Plots_0.4.svg)](http://pkg.julialang.org/?pkg=Plots&ver=0.4) -->
<!-- [![Coverage Status](https://coveralls.io/repos/tbreloff/Plots.jl/badge.svg?branch=master)](https://coveralls.io/r/tbreloff/Plots.jl?branch=master) -->
@@ -21,5 +22,3 @@ Plots is a plotting API and toolset. My goals with the package are:
- **Consistent**. Don't commit to one graphics package, use the same code everywhere.
- **Lightweight**. Very few dependencies.
- **Smart**. Attempts to figure out what you **want** it to do... not just what you **tell** it.
View the [full documentation](http://docs.juliaplots.org/latest).
+3 -3
View File
@@ -1,6 +1,6 @@
julia 0.7
julia 1.0
RecipesBase 0.2.3
RecipesBase 0.6.0
PlotUtils 0.4.1
PlotThemes 0.1.3
Reexport
@@ -13,4 +13,4 @@ JSON
NaNMath
Requires
Contour
GR 0.31.0
GR 0.34.0
+28 -23
View File
@@ -1,14 +1,23 @@
environment:
matrix:
# - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
# - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1
- julia_version: nightly
# matrix:
# allow_failures:
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
platform:
- x86 # 32-bit
- x64 # 64-bit
# # Uncomment the following lines to allow failures on nightly julia
# # (tests will run but not make your overall status red)
matrix:
allow_failures:
- julia_version: nightly
branches:
only:
- master
- /release-.*/
notifications:
- provider: Email
@@ -17,22 +26,18 @@ notifications:
on_build_status_changed: false
install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile($env:JULIA_URL, "C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))
build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo(); Pkg.clone(pwd(), \"Plots\"); Pkg.build(\"Plots\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
test_script:
# - C:\projects\julia\bin\julia -e "Pkg.test(\"Plots\")"
- C:\projects\julia\bin\julia -e "include(Pkg.dir(\"Plots\", \"test\", \"travis_commands.jl\"))"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
+2 -17
View File
@@ -5,6 +5,7 @@ using Reexport
import StaticArrays
using StaticArrays.FixedSizeArrays
using Dates, Printf, Statistics, Base64, LinearAlgebra
import SparseArrays: findnz
@reexport using RecipesBase
import RecipesBase: plot, plot!, animate
@@ -103,8 +104,6 @@ export
rotate,
rotate!,
center,
P2,
P3,
BezierCurve,
plotattr
@@ -117,7 +116,7 @@ ignorenan_minimum(x) = Base.minimum(x)
ignorenan_maximum(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.maximum(x)
ignorenan_maximum(x) = Base.maximum(x)
ignorenan_mean(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.mean(x)
ignorenan_mean(x) = Base.mean(x)
ignorenan_mean(x) = Statistics.mean(x)
ignorenan_extrema(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.extrema(x)
ignorenan_extrema(x) = Base.extrema(x)
@@ -294,18 +293,4 @@ end
const CURRENT_BACKEND = CurrentBackend(:none)
# for compatibility with Requires.jl:
@init begin
if isdefined(Main, :PLOTS_DEFAULTS)
if haskey(Main.PLOTS_DEFAULTS, :theme)
theme(Main.PLOTS_DEFAULTS[:theme])
end
for (k,v) in Main.PLOTS_DEFAULTS
k == :theme || default(k, v)
end
end
end
# ---------------------------------------------------------
end # module
+3 -3
View File
@@ -87,7 +87,7 @@ function buildanimation(animdir::AbstractString, fn::AbstractString,
run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -pix_fmt yuv420p -y $fn`)
end
show_msg && info("Saved animation to ", fn)
show_msg && @info("Saved animation to ", fn)
AnimatedGif(fn)
end
@@ -142,7 +142,7 @@ function _animate(forloop::Expr, args...; callgif = false)
end
push!(block.args, :(if $filterexpr; frame($animsym); end))
push!(block.args, :($countersym += 1))
push!(block.args, :(global $countersym += 1))
# add a final call to `gif(anim)`?
retval = callgif ? :(gif($animsym)) : animsym
@@ -151,7 +151,7 @@ function _animate(forloop::Expr, args...; callgif = false)
esc(quote
$freqassert # if filtering, check frequency is an Integer > 0
$animsym = Animation() # init animation object
$countersym = 1 # init iteration counter
global $countersym = 1 # init iteration counter
$forloop # for loop, saving a frame after each iteration
$retval # return the animation object, or the gif
end)
+2 -2
View File
@@ -27,8 +27,8 @@ const _arg_desc = KW(
:x => "Various. Input data. First Dimension",
:y => "Various. Input data. Second Dimension",
:z => "Various. Input data. Third Dimension. May be wrapped by a `Surface` for surface and heatmap types.",
:marker_z => "AbstractVector, Function `f(x,y,z) -> z_value`, or nothing. z-values for each series data point, which correspond to the color to be used from a markercolor gradient.",
:line_z => "AbstractVector, Function `f(x,y,z) -> z_value`, or nothing. z-values for each series line segment, which correspond to the color to be used from a linecolor gradient. Note that for N points, only the first N-1 values are used (one per line-segment).",
:marker_z => "AbstractVector, Function `f(x,y,z) -> z_value`, or Function `f(x,y) -> z_value`, or nothing. z-values for each series data point, which correspond to the color to be used from a markercolor gradient.",
:line_z => "AbstractVector, Function `f(x,y,z) -> z_value`, or Function `f(x,y) -> z_value`, or nothing. z-values for each series line segment, which correspond to the color to be used from a linecolor gradient. Note that for N points, only the first N-1 values are used (one per line-segment).",
:fill_z => "Matrix{Float64} of the same size as z matrix, which specifies the color of the 3D surface; the default value is `nothing`.",
:levels => "Integer, NTuple{2,Integer}. Number of levels (or x-levels/y-levels) for a contour type.",
:orientation => "Symbol. Horizontal or vertical orientation for bar types. Values `:h`, `:hor`, `:horizontal` correspond to horizontal (sideways, anchored to y-axis), and `:v`, `:vert`, and `:vertical` correspond to vertical (the default).",
+276 -275
View File
File diff suppressed because it is too large Load Diff
+56 -56
View File
@@ -8,7 +8,7 @@
function Axis(sp::Subplot, letter::Symbol, args...; kw...)
# init with values from _plot_defaults
d = KW(
plotattributes = KW(
:letter => letter,
# :extrema => (Inf, -Inf),
:extrema => Extrema(),
@@ -22,14 +22,14 @@ function Axis(sp::Subplot, letter::Symbol, args...; kw...)
for (k,v) in _axis_defaults
lk = Symbol(letter, k)
lv = _axis_defaults_byletter[lk]
d[k] = (lv == :match ? v : lv)
plotattributes[k] = (lv == :match ? v : lv)
end
# merge!(d, _axis_defaults)
d[:discrete_values] = []
# merge!(plotattributes, _axis_defaults)
plotattributes[:discrete_values] = []
# update the defaults
attr!(Axis([sp], d), args...; kw...)
attr!(Axis([sp], plotattributes), args...; kw...)
end
function get_axis(sp::Subplot, letter::Symbol)
@@ -41,45 +41,45 @@ function get_axis(sp::Subplot, letter::Symbol)
end::Axis
end
function process_axis_arg!(d::KW, arg, letter = "")
function process_axis_arg!(plotattributes::KW, arg, letter = "")
T = typeof(arg)
arg = get(_scaleAliases, arg, arg)
if typeof(arg) <: Font
d[Symbol(letter,:tickfont)] = arg
d[Symbol(letter,:guidefont)] = arg
plotattributes[Symbol(letter,:tickfont)] = arg
plotattributes[Symbol(letter,:guidefont)] = arg
elseif arg in _allScales
d[Symbol(letter,:scale)] = arg
plotattributes[Symbol(letter,:scale)] = arg
elseif arg in (:flip, :invert, :inverted)
d[Symbol(letter,:flip)] = true
plotattributes[Symbol(letter,:flip)] = true
elseif T <: AbstractString
d[Symbol(letter,:guide)] = arg
plotattributes[Symbol(letter,:guide)] = arg
# xlims/ylims
elseif (T <: Tuple || T <: AVec) && length(arg) == 2
sym = typeof(arg[1]) <: Number ? :lims : :ticks
d[Symbol(letter,sym)] = arg
plotattributes[Symbol(letter,sym)] = arg
# xticks/yticks
elseif T <: AVec
d[Symbol(letter,:ticks)] = arg
plotattributes[Symbol(letter,:ticks)] = arg
elseif arg == nothing
d[Symbol(letter,:ticks)] = []
plotattributes[Symbol(letter,:ticks)] = []
elseif T <: Bool || arg in _allShowaxisArgs
d[Symbol(letter,:showaxis)] = showaxis(arg, letter)
plotattributes[Symbol(letter,:showaxis)] = showaxis(arg, letter)
elseif typeof(arg) <: Number
d[Symbol(letter,:rotation)] = arg
plotattributes[Symbol(letter,:rotation)] = arg
elseif typeof(arg) <: Function
d[Symbol(letter,:formatter)] = arg
plotattributes[Symbol(letter,:formatter)] = arg
elseif !handleColors!(d, arg, Symbol(letter, :foreground_color_axis))
elseif !handleColors!(plotattributes, arg, Symbol(letter, :foreground_color_axis))
@warn("Skipped $(letter)axis arg $arg")
end
@@ -88,28 +88,28 @@ end
# update an Axis object with magic args and keywords
function attr!(axis::Axis, args...; kw...)
# first process args
d = axis.d
plotattributes = axis.plotattributes
for arg in args
process_axis_arg!(d, arg)
process_axis_arg!(plotattributes, arg)
end
# then override for any keywords... only those keywords that already exists in d
# then override for any keywords... only those keywords that already exists in plotattributes
for (k,v) in kw
if haskey(d, k)
if haskey(plotattributes, k)
if k == :discrete_values
# add these discrete values to the axis
for vi in v
discrete_value!(axis, vi)
end
else
d[k] = v
plotattributes[k] = v
end
end
end
# replace scale aliases
if haskey(_scaleAliases, d[:scale])
d[:scale] = _scaleAliases[d[:scale]]
if haskey(_scaleAliases, plotattributes[:scale])
plotattributes[:scale] = _scaleAliases[plotattributes[:scale]]
end
axis
@@ -117,10 +117,10 @@ end
# -------------------------------------------------------------------------
Base.show(io::IO, axis::Axis) = dumpdict(axis.d, "Axis", true)
# Base.getindex(axis::Axis, k::Symbol) = getindex(axis.d, k)
Base.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.d, v, ks...)
Base.haskey(axis::Axis, k::Symbol) = haskey(axis.d, k)
Base.show(io::IO, axis::Axis) = dumpdict(axis.plotattributes, "Axis", true)
# Base.getindex(axis::Axis, k::Symbol) = getindex(axis.plotattributes, k)
Base.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.plotattributes, v, ks...)
Base.haskey(axis::Axis, k::Symbol) = haskey(axis.plotattributes, k)
ignorenan_extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax))
@@ -290,9 +290,9 @@ function get_minor_ticks(axis,ticks)
axis[:minorticks] in (nothing, false) && !axis[:minorgrid] && return nothing
ticks = ticks[1]
length(ticks) < 2 && return nothing
amin, amax = axis_limits(axis)
#Add one phantom tick either side of the ticks to ensure minor ticks extend to the axis limits
#Add one phantom tick either side of the ticks to ensure minor ticks extend to the axis limits
if length(ticks) > 2
ratio = (ticks[3] - ticks[2])/(ticks[2] - ticks[1])
elseif axis[:scale] == :none
@@ -322,7 +322,7 @@ function reset_extrema!(sp::Subplot)
sp[Symbol(asym,:axis)][:extrema] = Extrema()
end
for series in sp.series_list
expand_extrema!(sp, series.d)
expand_extrema!(sp, series.plotattributes)
end
end
@@ -357,17 +357,17 @@ function expand_extrema!(axis::Axis, v::AVec{N}) where N<:Number
end
function expand_extrema!(sp::Subplot, d::KW)
vert = isvertical(d)
function expand_extrema!(sp::Subplot, plotattributes::KW)
vert = isvertical(plotattributes)
# first expand for the data
for letter in (:x, :y, :z)
data = d[if vert
data = plotattributes[if vert
letter
else
letter == :x ? :y : letter == :y ? :x : :z
end]
if letter != :z && d[:seriestype] == :straightline && any(series[:seriestype] != :straightline for series in series_list(sp)) && data[1] != data[2]
if letter != :z && plotattributes[:seriestype] == :straightline && any(series[:seriestype] != :straightline for series in series_list(sp)) && data[1] != data[2]
data = [NaN]
end
axis = sp[Symbol(letter, "axis")]
@@ -379,30 +379,30 @@ function expand_extrema!(sp::Subplot, d::KW)
elseif eltype(data) <: Number || (isa(data, Surface) && all(di -> isa(di, Number), data.surf))
if !(eltype(data) <: Number)
# huh... must have been a mis-typed surface? lets swap it out
data = d[letter] = Surface(Matrix{Float64}(data.surf))
data = plotattributes[letter] = Surface(Matrix{Float64}(data.surf))
end
expand_extrema!(axis, data)
elseif data != nothing
# TODO: need more here... gotta track the discrete reference value
# as well as any coord offset (think of boxplot shape coords... they all
# correspond to the same x-value)
d[letter], d[Symbol(letter,"_discrete_indices")] = discrete_value!(axis, data)
expand_extrema!(axis, d[letter])
plotattributes[letter], plotattributes[Symbol(letter,"_discrete_indices")] = discrete_value!(axis, data)
expand_extrema!(axis, plotattributes[letter])
end
end
# # expand for fillrange/bar_width
# fillaxis, baraxis = sp.attr[:yaxis], sp.attr[:xaxis]
# if isvertical(d)
# if isvertical(plotattributes)
# fillaxis, baraxis = baraxis, fillaxis
# end
# expand for fillrange
fr = d[:fillrange]
if fr == nothing && d[:seriestype] == :bar
fr = plotattributes[:fillrange]
if fr == nothing && plotattributes[:seriestype] == :bar
fr = 0.0
end
if fr != nothing && !all3D(d)
if fr != nothing && !all3D(plotattributes)
axis = sp.attr[vert ? :yaxis : :xaxis]
if typeof(fr) <: Tuple
for fri in fr
@@ -414,13 +414,13 @@ function expand_extrema!(sp::Subplot, d::KW)
end
# expand for bar_width
if d[:seriestype] == :bar
if plotattributes[:seriestype] == :bar
dsym = vert ? :x : :y
data = d[dsym]
data = plotattributes[dsym]
bw = d[:bar_width]
bw = plotattributes[:bar_width]
if bw == nothing
bw = d[:bar_width] = _bar_width * ignorenan_minimum(filter(x->x>0,diff(sort(data))))
bw = plotattributes[:bar_width] = _bar_width * ignorenan_minimum(filter(x->x>0,diff(sort(data))))
end
axis = sp.attr[Symbol(dsym, :axis)]
expand_extrema!(axis, ignorenan_maximum(data) + 0.5maximum(bw))
@@ -428,11 +428,11 @@ function expand_extrema!(sp::Subplot, d::KW)
end
# expand for heatmaps
if d[:seriestype] == :heatmap
if plotattributes[:seriestype] == :heatmap
for letter in (:x, :y)
data = d[letter]
data = plotattributes[letter]
axis = sp[Symbol(letter, "axis")]
scale = get(d, Symbol(letter, "scale"), :identity)
scale = get(plotattributes, Symbol(letter, "scale"), :identity)
expand_extrema!(axis, heatmap_edges(data, scale))
end
end
@@ -462,7 +462,7 @@ function default_should_widen(axis::Axis)
if !is_2tuple(axis[:lims])
for sp in axis.sps
for series in series_list(sp)
if series.d[:seriestype] in _widen_seriestypes
if series.plotattributes[:seriestype] in _widen_seriestypes
should_widen = true
end
end
@@ -572,12 +572,12 @@ end
# -------------------------------------------------------------------------
function pie_labels(sp::Subplot, series::Series)
d = series.d
if haskey(d,:x_discrete_indices)
dvals = sp.attr[:xaxis].d[:discrete_values]
[dvals[idx] for idx in d[:x_discrete_indices]]
plotattributes = series.plotattributes
if haskey(plotattributes,:x_discrete_indices)
dvals = sp.attr[:xaxis].plotattributes[:discrete_values]
[dvals[idx] for idx in plotattributes[:x_discrete_indices]]
else
d[:x]
plotattributes[:x]
end
end
+5 -2
View File
@@ -43,7 +43,7 @@ end
# ---------------------------------------------------------
function add_backend(pkg::Symbol)
info("To do a standard install of $pkg, copy and run this:\n\n")
@info("To do a standard install of $pkg, copy and run this:\n\n")
println(add_backend_string(_backend_instance(pkg)))
println()
end
@@ -387,7 +387,7 @@ end
function _initialize_backend(::PyPlotBackend)
@eval Main begin
import PyPlot, PyCall
import LaTeXStrings: latexstring
import LaTeXStrings
export PyPlot
@@ -400,7 +400,10 @@ function add_backend_string(::PyPlotBackend)
"""
using Pkg
Pkg.add("PyPlot")
Pkg.add("PyCall")
Pkg.add("LaTeXStrings")
withenv("PYTHON" => "") do
Pkg.build("PyCall")
Pkg.build("PyPlot")
end
"""
+162 -162
View File
@@ -182,7 +182,7 @@ function gl_marker(shape::Symbol)
end
end
function extract_limits(sp, d, kw_args)
function extract_limits(sp, plotattributes, kw_args)
clims = sp[:clims]
if is_2tuple(clims)
if isfinite(clims[1]) && isfinite(clims[2])
@@ -200,70 +200,70 @@ to_vec(::Type{T}, vec::StaticArrays.StaticVector{2}) where {T <: StaticArrays.St
to_vec(::Type{T}, vecs::AbstractVector) where {T <: StaticArrays.StaticVector} = map(x-> to_vec(T, x), vecs)
function extract_marker(d, kw_args)
dim = Plots.is3d(d) ? 3 : 2
function extract_marker(plotattributes, kw_args)
dim = Plots.is3d(plotattributes) ? 3 : 2
scaling = dim == 3 ? 0.003 : 2
if haskey(d, :markershape)
shape = d[:markershape]
if haskey(plotattributes, :markershape)
shape = plotattributes[:markershape]
shape = gl_marker(shape)
if shape != :none
kw_args[:primitive] = shape
end
end
dim = isa(kw_args[:primitive], GLVisualize.Sprites) ? 2 : 3
if haskey(d, :markersize)
msize = d[:markersize]
if haskey(plotattributes, :markersize)
msize = plotattributes[:markersize]
kw_args[:scale] = to_vec(GeometryTypes.Vec{dim, Float32}, msize .* scaling)
end
if haskey(d, :offset)
kw_args[:offset] = d[:offset]
if haskey(plotattributes, :offset)
kw_args[:offset] = plotattributes[:offset]
end
# get the color
key = :markercolor
haskey(d, key) || return
c = gl_color(d[key])
if isa(c, AbstractVector) && d[:marker_z] != nothing
extract_colornorm(d, kw_args)
haskey(plotattributes, key) || return
c = gl_color(plotattributes[key])
if isa(c, AbstractVector) && plotattributes[:marker_z] != nothing
extract_colornorm(plotattributes, kw_args)
kw_args[:color] = nothing
kw_args[:color_map] = c
kw_args[:intensity] = convert(Vector{Float32}, d[:marker_z])
kw_args[:intensity] = convert(Vector{Float32}, plotattributes[:marker_z])
else
kw_args[:color] = c
end
key = :markerstrokecolor
haskey(d, key) || return
c = gl_color(d[key])
haskey(plotattributes, key) || return
c = gl_color(plotattributes[key])
if c != nothing
if !(isa(c, Colorant) || (isa(c, Vector) && eltype(c) <: Colorant))
error("Stroke Color not supported: $c")
end
kw_args[:stroke_color] = c
kw_args[:stroke_width] = Float32(d[:markerstrokewidth])
kw_args[:stroke_width] = Float32(plotattributes[:markerstrokewidth])
end
end
function _extract_surface(d::Plots.Surface)
d.surf
function _extract_surface(plotattributes::Plots.Surface)
plotattributes.surf
end
function _extract_surface(d::AbstractArray)
d
function _extract_surface(plotattributes::AbstractArray)
plotattributes
end
# TODO when to transpose??
function extract_surface(d)
map(_extract_surface, (d[:x], d[:y], d[:z]))
function extract_surface(plotattributes)
map(_extract_surface, (plotattributes[:x], plotattributes[:y], plotattributes[:z]))
end
function topoints(::Type{P}, array) where P
[P(x) for x in zip(array...)]
end
function extract_points(d)
dim = is3d(d) ? 3 : 2
array = if d[:seriestype] == :straightline
straightline_data(d)
elseif d[:seriestype] == :shape
shape_data(d)
function extract_points(plotattributes)
dim = is3d(plotattributes) ? 3 : 2
array = if plotattributes[:seriestype] == :straightline
straightline_data(plotattributes)
elseif plotattributes[:seriestype] == :shape
shape_data(plotattributes)
else
(d[:x], d[:y], d[:z])[1:dim]
(plotattributes[:x], plotattributes[:y], plotattributes[:z])[1:dim]
end
topoints(Point{dim, Float32}, array)
end
@@ -275,50 +275,50 @@ function make_gradient(grad::ColorGradient)
end
make_gradient(c) = make_gradient(cgrad())
function extract_any_color(d, kw_args)
if d[:marker_z] == nothing
c = scalar_color(d, :fill)
extract_c(d, kw_args, :fill)
function extract_any_color(plotattributes, kw_args)
if plotattributes[:marker_z] == nothing
c = scalar_color(plotattributes, :fill)
extract_c(plotattributes, kw_args, :fill)
if isa(c, Colorant)
kw_args[:color] = c
else
kw_args[:color] = nothing
kw_args[:color_map] = make_gradient(c)
clims = d[:subplot][:clims]
clims = plotattributes[:subplot][:clims]
if Plots.is_2tuple(clims)
if isfinite(clims[1]) && isfinite(clims[2])
kw_args[:color_norm] = Vec2f0(clims)
end
elseif clims == :auto
kw_args[:color_norm] = Vec2f0(ignorenan_extrema(d[:y]))
kw_args[:color_norm] = Vec2f0(ignorenan_extrema(plotattributes[:y]))
end
end
else
kw_args[:color] = nothing
clims = d[:subplot][:clims]
clims = plotattributes[:subplot][:clims]
if Plots.is_2tuple(clims)
if isfinite(clims[1]) && isfinite(clims[2])
kw_args[:color_norm] = Vec2f0(clims)
end
elseif clims == :auto
kw_args[:color_norm] = Vec2f0(ignorenan_extrema(d[:y]))
kw_args[:color_norm] = Vec2f0(ignorenan_extrema(plotattributes[:y]))
else
error("Unsupported limits: $clims")
end
kw_args[:intensity] = convert(Vector{Float32}, d[:marker_z])
kw_args[:color_map] = gl_color_map(d, :marker)
kw_args[:intensity] = convert(Vector{Float32}, plotattributes[:marker_z])
kw_args[:color_map] = gl_color_map(plotattributes, :marker)
end
end
function extract_stroke(d, kw_args)
extract_c(d, kw_args, :line)
if haskey(d, :linewidth)
kw_args[:thickness] = Float32(d[:linewidth] * 3)
function extract_stroke(plotattributes, kw_args)
extract_c(plotattributes, kw_args, :line)
if haskey(plotattributes, :linewidth)
kw_args[:thickness] = Float32(plotattributes[:linewidth] * 3)
end
end
function extract_color(d, sym)
d[Symbol("$(sym)color")]
function extract_color(plotattributes, sym)
plotattributes[Symbol("$(sym)color")]
end
gl_color(c::PlotUtils.ColorGradient) = c.colors
@@ -335,12 +335,12 @@ function gl_color(c, a)
c = convertColor(c, a)
RGBA{Float32}(c)
end
function scalar_color(d, sym)
gl_color(extract_color(d, sym))
function scalar_color(plotattributes, sym)
gl_color(extract_color(plotattributes, sym))
end
function gl_color_map(d, sym)
colors = extract_color(d, sym)
function gl_color_map(plotattributes, sym)
colors = extract_color(plotattributes, sym)
_gl_color_map(colors)
end
function _gl_color_map(colors::PlotUtils.ColorGradient)
@@ -377,10 +377,10 @@ function insert_pattern!(points, kw_args)
kw_args[:pattern] = tex
kw_args[:pattern_length] = Float32(last(points))
end
function extract_linestyle(d, kw_args)
haskey(d, :linestyle) || return
ls = d[:linestyle]
lw = d[:linewidth]
function extract_linestyle(plotattributes, kw_args)
haskey(plotattributes, :linestyle) || return
ls = plotattributes[:linestyle]
lw = plotattributes[:linewidth]
kw_args[:thickness] = Float32(lw)
if ls == :dash
points = [0.0, lw, 2lw, 3lw, 4lw]
@@ -400,7 +400,7 @@ function extract_linestyle(d, kw_args)
points = [0.0, dtick, dtick+dgap, dtick+dgap+ptick, dtick+dgap+ptick+pgap, dtick+dgap+ptick+pgap+ptick, dtick+dgap+ptick+pgap+ptick+pgap]
insert_pattern!(points, kw_args)
end
extract_c(d, kw_args, :line)
extract_c(plotattributes, kw_args, :line)
nothing
end
@@ -467,8 +467,8 @@ function hover(to_hover, to_display, window)
nothing
end
function extract_extrema(d, kw_args)
xmin, xmax = ignorenan_extrema(d[:x]); ymin, ymax = ignorenan_extrema(d[:y])
function extract_extrema(plotattributes, kw_args)
xmin, xmax = ignorenan_extrema(plotattributes[:x]); ymin, ymax = ignorenan_extrema(plotattributes[:y])
kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(xmin, ymin, xmax-xmin, ymax-ymin)
nothing
end
@@ -479,50 +479,50 @@ function extract_font(font, kw_args)
kw_args[:color] = gl_color(font.color)
end
function extract_colornorm(d, kw_args)
clims = d[:subplot][:clims]
function extract_colornorm(plotattributes, kw_args)
clims = plotattributes[:subplot][:clims]
if Plots.is_2tuple(clims)
if isfinite(clims[1]) && isfinite(clims[2])
kw_args[:color_norm] = Vec2f0(clims)
end
elseif clims == :auto
z = if haskey(d, :marker_z) && d[:marker_z] != nothing
d[:marker_z]
elseif haskey(d, :line_z) && d[:line_z] != nothing
d[:line_z]
elseif isa(d[:z], Plots.Surface)
d[:z].surf
z = if haskey(plotattributes, :marker_z) && plotattributes[:marker_z] != nothing
plotattributes[:marker_z]
elseif haskey(plotattributes, :line_z) && plotattributes[:line_z] != nothing
plotattributes[:line_z]
elseif isa(plotattributes[:z], Plots.Surface)
plotattributes[:z].surf
else
d[:y]
plotattributes[:y]
end
kw_args[:color_norm] = Vec2f0(ignorenan_extrema(z))
kw_args[:intensity] = map(Float32, collect(z))
end
end
function extract_gradient(d, kw_args, sym)
function extract_gradient(plotattributes, kw_args, sym)
key = Symbol("$(sym)color")
haskey(d, key) || return
c = make_gradient(d[key])
haskey(plotattributes, key) || return
c = make_gradient(plotattributes[key])
kw_args[:color] = nothing
extract_colornorm(d, kw_args)
extract_colornorm(plotattributes, kw_args)
kw_args[:color_map] = c
return
end
function extract_c(d, kw_args, sym)
function extract_c(plotattributes, kw_args, sym)
key = Symbol("$(sym)color")
haskey(d, key) || return
c = gl_color(d[key])
haskey(plotattributes, key) || return
c = gl_color(plotattributes[key])
kw_args[:color] = nothing
kw_args[:color_map] = nothing
kw_args[:color_norm] = nothing
if (
isa(c, AbstractVector) &&
((haskey(d, :marker_z) && d[:marker_z] != nothing) ||
(haskey(d, :line_z) && d[:line_z] != nothing))
((haskey(plotattributes, :marker_z) && plotattributes[:marker_z] != nothing) ||
(haskey(plotattributes, :line_z) && plotattributes[:line_z] != nothing))
)
extract_colornorm(d, kw_args)
extract_colornorm(plotattributes, kw_args)
kw_args[:color_map] = c
else
kw_args[:color] = c
@@ -530,16 +530,16 @@ function extract_c(d, kw_args, sym)
return
end
function extract_stroke(d, kw_args, sym)
function extract_stroke(plotattributes, kw_args, sym)
key = Symbol("$(sym)strokecolor")
haskey(d, key) || return
c = gl_color(d[key])
haskey(plotattributes, key) || return
c = gl_color(plotattributes[key])
if c != nothing
if !isa(c, Colorant)
error("Stroke Color not supported: $c")
end
kw_args[:stroke_color] = c
kw_args[:stroke_width] = Float32(d[Symbol("$(sym)strokewidth")]) * 2
kw_args[:stroke_width] = Float32(plotattributes[Symbol("$(sym)strokewidth")]) * 2
end
return
end
@@ -551,12 +551,12 @@ function draw_grid_lines(sp, grid_segs, thickness, style, model, color)
kw_args = Dict{Symbol, Any}(
:model => model
)
d = Dict(
plotattributes = Dict(
:linestyle => style,
:linewidth => Float32(thickness),
:linecolor => color
)
Plots.extract_linestyle(d, kw_args)
Plots.extract_linestyle(plotattributes, kw_args)
GL.gl_lines(map(Point2f0, grid_segs.pts), kw_args)
end
@@ -808,10 +808,10 @@ function gl_draw_axes_3d(sp, model)
)
end
function gl_bar(d, kw_args)
x, y = d[:x], d[:y]
function gl_bar(plotattributes, kw_args)
x, y = plotattributes[:x], plotattributes[:y]
nx, ny = length(x), length(y)
axis = d[:subplot][isvertical(d) ? :xaxis : :yaxis]
axis = plotattributes[:subplot][isvertical(plotattributes) ? :xaxis : :yaxis]
cv = [discrete_value!(axis, xi)[1] for xi=x]
x = if nx == ny
cv
@@ -832,18 +832,18 @@ function gl_bar(d, kw_args)
end
# make fillto a vector... default fills to 0
fillto = d[:fillrange]
fillto = plotattributes[:fillrange]
if fillto == nothing
fillto = 0
end
# create the bar shapes by adding x/y segments
positions, scales = Array{Point2f0}(ny), Array{Vec2f0}(ny)
positions, scales = Array{Point2f0}(undef, ny), Array{Vec2f0}(undef, ny)
m = Reactive.value(kw_args[:model])
sx, sy = m[1,1], m[2,2]
for i=1:ny
center = x[i]
hwi = abs(_cycle(hw,i)); yi = y[i]; fi = _cycle(fillto,i)
if Plots.isvertical(d)
if Plots.isvertical(plotattributes)
sz = (hwi*sx, yi*sy)
else
sz = (yi*sx, hwi*2*sy)
@@ -862,10 +862,10 @@ const _box_halfwidth = 0.4
notch_width(q2, q4, N) = 1.58 * (q4-q2)/sqrt(N)
function gl_boxplot(d, kw_args)
function gl_boxplot(plotattributes, kw_args)
kwbox = copy(kw_args)
range = 1.5; notch = false
x, y = d[:x], d[:y]
x, y = plotattributes[:x], plotattributes[:y]
glabels = sort(collect(unique(x)))
warning = false
outliers_x, outliers_y = zeros(0), zeros(0)
@@ -890,8 +890,8 @@ function gl_boxplot(d, kw_args)
end
# make the shape
center = Plots.discrete_value!(d[:subplot][:xaxis], glabel)[1]
hw = d[:bar_width] == nothing ? Plots._box_halfwidth*2 : _cycle(d[:bar_width], i)
center = Plots.discrete_value!(plotattributes[:subplot][:xaxis], glabel)[1]
hw = plotattributes[:bar_width] == nothing ? Plots._box_halfwidth*2 : _cycle(plotattributes[:bar_width], i)
l, m, r = center - hw/2, center, center + hw/2
# internal nodes for notches
@@ -930,17 +930,17 @@ function gl_boxplot(d, kw_args)
:model => kw_args[:model],
:offset => Vec2f0(0),
)
extract_marker(d, kw_args)
extract_marker(plotattributes, kw_args)
outlier_kw = Dict(
:model => kw_args[:model],
:color => scalar_color(d, :fill),
:stroke_width => Float32(d[:markerstrokewidth]),
:stroke_color => scalar_color(d, :markerstroke),
:color => scalar_color(plotattributes, :fill),
:stroke_width => Float32(plotattributes[:markerstrokewidth]),
:stroke_color => scalar_color(plotattributes, :markerstroke),
)
lines_kw = Dict(
:model => kw_args[:model],
:stroke_width => d[:linewidth],
:stroke_color => scalar_color(d, :fill),
:stroke_width => plotattributes[:linewidth],
:stroke_color => scalar_color(plotattributes, :fill),
)
vis1 = GLVisualize.visualize((GLVisualize.RECTANGLE, box_pos), Style(:default), kwbox)
vis2 = GLVisualize.visualize((GLVisualize.CIRCLE, outliers), Style(:default), outlier_kw)
@@ -988,7 +988,7 @@ function scale_for_annotations!(series::Series, scaletype::Symbol = :pixels)
# we use baseshape to overwrite the markershape attribute
# with a list of custom shapes for each
msw, msh = anns.scalefactor
offsets = Array{Vec2f0}(length(anns.strs))
offsets = Array{Vec2f0}(undef, length(anns.strs))
series[:markersize] = map(1:length(anns.strs)) do i
str = _cycle(anns.strs, i)
# get the width and height of the string (in mm)
@@ -1066,8 +1066,8 @@ function _display(plt::Plot{GLVisualizeBackend}, visible = true)
end
for series in Plots.series_list(sp)
d = series.d
st = d[:seriestype]; kw_args = KW() # exctract kw
plotattributes = series.plotattributes
st = plotattributes[:seriestype]; kw_args = KW() # exctract kw
kw_args[:model] = model_m # add transformation
if !_3d # 3D is treated differently, since we need boundingboxes for camera
@@ -1075,80 +1075,80 @@ function _display(plt::Plot{GLVisualizeBackend}, visible = true)
end
scale_for_annotations!(series)
if st in (:surface, :wireframe)
x, y, z = extract_surface(d)
extract_gradient(d, kw_args, :fill)
z = Plots.transpose_z(d, z, false)
x, y, z = extract_surface(plotattributes)
extract_gradient(plotattributes, kw_args, :fill)
z = Plots.transpose_z(plotattributes, z, false)
if isa(x, AbstractMatrix) && isa(y, AbstractMatrix)
x, y = Plots.transpose_z(d, x, false), Plots.transpose_z(d, y, false)
x, y = Plots.transpose_z(plotattributes, x, false), Plots.transpose_z(plotattributes, y, false)
end
if st == :wireframe
kw_args[:wireframe] = true
kw_args[:stroke_color] = d[:linecolor]
kw_args[:stroke_width] = Float32(d[:linewidth]/100f0)
kw_args[:stroke_color] = plotattributes[:linecolor]
kw_args[:stroke_width] = Float32(plotattributes[:linewidth]/100f0)
end
vis = GL.gl_surface(x, y, z, kw_args)
elseif (st in (:path, :path3d, :straightline)) && d[:linewidth] > 0
elseif (st in (:path, :path3d, :straightline)) && plotattributes[:linewidth] > 0
kw = copy(kw_args)
points = Plots.extract_points(d)
extract_linestyle(d, kw)
points = Plots.extract_points(plotattributes)
extract_linestyle(plotattributes, kw)
vis = GL.gl_lines(points, kw)
if d[:markershape] != :none
if plotattributes[:markershape] != :none
kw = copy(kw_args)
extract_stroke(d, kw)
extract_marker(d, kw)
extract_stroke(plotattributes, kw)
extract_marker(plotattributes, kw)
vis2 = GL.gl_scatter(copy(points), kw)
vis = [vis; vis2]
end
if d[:fillrange] != nothing
if plotattributes[:fillrange] != nothing
kw = copy(kw_args)
fr = d[:fillrange]
ps = if all(x-> x >= 0, diff(d[:x])) # if is monotonic
fr = plotattributes[:fillrange]
ps = if all(x-> x >= 0, diff(plotattributes[:x])) # if is monotonic
vcat(points, Point2f0[(points[i][1], _cycle(fr, i)) for i=length(points):-1:1])
else
points
end
extract_c(d, kw, :fill)
extract_c(plotattributes, kw, :fill)
vis = [GL.gl_poly(ps, kw), vis]
end
elseif st in (:scatter, :scatter3d) #|| d[:markershape] != :none
extract_marker(d, kw_args)
points = extract_points(d)
elseif st in (:scatter, :scatter3d) #|| plotattributes[:markershape] != :none
extract_marker(plotattributes, kw_args)
points = extract_points(plotattributes)
vis = GL.gl_scatter(points, kw_args)
elseif st == :shape
extract_c(d, kw_args, :fill)
vis = GL.gl_shape(d, kw_args)
extract_c(plotattributes, kw_args, :fill)
vis = GL.gl_shape(plotattributes, kw_args)
elseif st == :contour
x,y,z = extract_surface(d)
z = transpose_z(d, z, false)
extract_extrema(d, kw_args)
extract_gradient(d, kw_args, :fill)
kw_args[:fillrange] = d[:fillrange]
kw_args[:levels] = d[:levels]
x,y,z = extract_surface(plotattributes)
z = transpose_z(plotattributes, z, false)
extract_extrema(plotattributes, kw_args)
extract_gradient(plotattributes, kw_args, :fill)
kw_args[:fillrange] = plotattributes[:fillrange]
kw_args[:levels] = plotattributes[:levels]
vis = GL.gl_contour(x,y,z, kw_args)
elseif st == :heatmap
x,y,z = extract_surface(d)
extract_gradient(d, kw_args, :fill)
extract_extrema(d, kw_args)
extract_limits(sp, d, kw_args)
x,y,z = extract_surface(plotattributes)
extract_gradient(plotattributes, kw_args, :fill)
extract_extrema(plotattributes, kw_args)
extract_limits(sp, plotattributes, kw_args)
vis = GL.gl_heatmap(x,y,z, kw_args)
elseif st == :bar
extract_c(d, kw_args, :fill)
extract_stroke(d, kw_args, :marker)
vis = gl_bar(d, kw_args)
extract_c(plotattributes, kw_args, :fill)
extract_stroke(plotattributes, kw_args, :marker)
vis = gl_bar(plotattributes, kw_args)
elseif st == :image
extract_extrema(d, kw_args)
vis = GL.gl_image(d[:z].surf, kw_args)
extract_extrema(plotattributes, kw_args)
vis = GL.gl_image(plotattributes[:z].surf, kw_args)
elseif st == :boxplot
extract_c(d, kw_args, :fill)
vis = gl_boxplot(d, kw_args)
extract_c(plotattributes, kw_args, :fill)
vis = gl_boxplot(plotattributes, kw_args)
elseif st == :volume
volume = d[:y]
_d = copy(d)
_d[:y] = 0:1
_d[:x] = 0:1
volume = plotattributes[:y]
_plotattributes = copy(plotattributes)
_plotattributes[:y] = 0:1
_plotattributes[:x] = 0:1
kw_args = KW()
extract_gradient(_d, kw_args, :fill)
extract_gradient(_plotattributes, kw_args, :fill)
vis = visualize(volume.v, Style(:default), kw_args)
else
error("failed to display plot type $st")
@@ -1157,15 +1157,15 @@ function _display(plt::Plot{GLVisualizeBackend}, visible = true)
isa(vis, Array) && isempty(vis) && continue # nothing to see here
GLVisualize._view(vis, sp_screen, camera=:perspective)
if haskey(d, :hover) && !(d[:hover] in (false, :none, nothing))
hover(vis, d[:hover], sp_screen)
if haskey(plotattributes, :hover) && !(plotattributes[:hover] in (false, :none, nothing))
hover(vis, plotattributes[:hover], sp_screen)
end
if isdefined(:GLPlot) && isdefined(Main.GLPlot, :(register_plot!))
del_signal = Main.GLPlot.register_plot!(vis, sp_screen, create_gizmo=false)
append!(_glplot_deletes, del_signal)
end
anns = series[:series_annotations]
for (x, y, str, font) in EachAnn(anns, d[:x], d[:y])
for (x, y, str, font) in EachAnn(anns, plotattributes[:x], plotattributes[:y])
txt_args = Dict{Symbol, Any}(:model => eye(GLAbstraction.Mat4f0))
x, y = Reactive.value(model_m) * GeometryTypes.Vec{4, Float32}(x, y, 0, 1)
extract_font(font, txt_args)
@@ -1241,10 +1241,10 @@ function gl_lines(points, kw_args)
return result
end
function gl_shape(d, kw_args)
points = Plots.extract_points(d)
function gl_shape(plotattributes, kw_args)
points = Plots.extract_points(plotattributes)
result = []
for rng in iter_segments(d[:x], d[:y])
for rng in iter_segments(plotattributes[:x], plotattributes[:y])
ps = points[rng]
meshes = gl_poly(ps, kw_args)
append!(result, meshes)
@@ -1398,10 +1398,10 @@ end
"""
Ugh, so much special casing (╯°□°)╯︵ ┻━┻
"""
function label_scatter(d, w, ho)
function label_scatter(plotattributes, w, ho)
kw = KW()
extract_stroke(d, kw)
extract_marker(d, kw)
extract_stroke(plotattributes, kw)
extract_marker(plotattributes, kw)
kw[:scale] = Vec2f0(w/2)
kw[:offset] = Vec2f0(-w/4)
if haskey(kw, :intensity)
@@ -1442,21 +1442,21 @@ function make_label(sp, series, i)
GL = Plots
w, gap, ho = 20f0, 5f0, 5
result = []
d = series.d
st = d[:seriestype]
plotattributes = series.plotattributes
st = plotattributes[:seriestype]
kw_args = KW()
if (st in (:path, :path3d, :straightline)) && d[:linewidth] > 0
if (st in (:path, :path3d, :straightline)) && plotattributes[:linewidth] > 0
points = Point2f0[(0, ho), (w, ho)]
kw = KW()
extract_linestyle(d, kw)
extract_linestyle(plotattributes, kw)
append!(result, GL.gl_lines(points, kw))
if d[:markershape] != :none
push!(result, label_scatter(d, w, ho))
if plotattributes[:markershape] != :none
push!(result, label_scatter(plotattributes, w, ho))
end
elseif st in (:scatter, :scatter3d) #|| d[:markershape] != :none
push!(result, label_scatter(d, w, ho))
elseif st in (:scatter, :scatter3d) #|| plotattributes[:markershape] != :none
push!(result, label_scatter(plotattributes, w, ho))
else
extract_c(d, kw_args, :fill)
extract_c(plotattributes, kw_args, :fill)
if isa(kw_args[:color], AbstractVector)
kw_args[:color] = first(kw_args[:color])
end
+51 -36
View File
@@ -18,6 +18,7 @@ const _gr_attr = merge_with_base_supported([
:layout,
:title, :window_title,
:guide, :lims, :ticks, :scale, :flip,
:match_dimensions,
:titlefontfamily, :titlefontsize, :titlefonthalign, :titlefontvalign,
:titlefontrotation, :titlefontcolor,
:legendfontfamily, :legendfontsize, :legendfonthalign, :legendfontvalign,
@@ -27,7 +28,7 @@ const _gr_attr = merge_with_base_supported([
:guidefontfamily, :guidefontsize, :guidefonthalign, :guidefontvalign,
:guidefontrotation, :guidefontcolor,
:grid, :gridalpha, :gridstyle, :gridlinewidth,
:legend, :legendtitle, :colorbar,
:legend, :legendtitle, :colorbar, :colorbar_title,
:fill_z, :line_z, :marker_z, :levels,
:ribbon, :quiver,
:orientation,
@@ -338,7 +339,11 @@ end
# draw the markers, one at a time
function gr_draw_markers(series::Series, x, y, msize, mz)
function gr_draw_markers(series::Series, x, y, clims, msize = series[:markersize])
isempty(x) && return
GR.setfillintstyle(GR.INTSTYLE_SOLID)
shapes = series[:markershape]
if shapes != :none
for i=1:length(x)
@@ -355,7 +360,7 @@ function gr_draw_markers(series::Series, x, y, msize, mz)
# draw the shape - don't draw filled area if marker shape is 1D
if !(shape in (:hline, :vline, :+, :x))
cfunc(get_markercolor(series, i))
cfunc(get_markercolor(series, clims, i))
gr_set_transparency(get_markeralpha(series, i))
gr_draw_marker(x[i], y[i], msi, shape)
end
@@ -363,13 +368,6 @@ function gr_draw_markers(series::Series, x, y, msize, mz)
end
end
function gr_draw_markers(series::Series, x, y, clims)
isempty(x) && return
mz = normalize_zvals(series[:marker_z], clims)
GR.setfillintstyle(GR.INTSTYLE_SOLID)
gr_draw_markers(series, x, y, series[:markersize], mz)
end
# ---------------------------------------------------------
function gr_set_line(lw, style, c) #, a)
@@ -421,6 +419,8 @@ const viewport_plotarea = zeros(4)
# the size of the current plot in pixels
const gr_plot_size = [600.0, 400.0]
const gr_colorbar_ratio = 0.1
function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, viewport_canvas)
viewport = zeros(4)
viewport[1] = viewport_canvas[2] * (left(bb) / w)
@@ -436,7 +436,7 @@ function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, vi
viewport[4] = 0.5 * (vp[3] + vp[4] + extent)
end
if hascolorbar(sp)
viewport[2] -= 0.1
viewport[2] -= gr_colorbar_ratio
end
viewport
end
@@ -483,6 +483,13 @@ function gr_colorbar(sp::Subplot, clims)
GR.cellarray(xmin, xmax, clims[2], clims[1], 1, length(l), l)
ztick = 0.5 * GR.tick(clims[1], clims[2])
GR.axes(0, ztick, xmax, clims[1], 0, 1, 0.005)
gr_set_font(guidefont(sp[:yaxis]))
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP)
GR.setcharup(-1, 0)
gr_text(viewport_plotarea[2] + gr_colorbar_ratio,
gr_view_ycenter(), sp[:colorbar_title])
gr_set_viewport_plotarea()
end
@@ -537,6 +544,9 @@ function gr_display(plt::Plot, fmt="")
_gr_thickness_scaling[1] = plt[:thickness_scaling]
dpi_factor = plt[:dpi] / Plots.DPI
if fmt == "svg"
dpi_factor *= 4
end
# collect some monitor/display sizes in meters and pixels
display_width_meters, display_height_meters, display_width_px, display_height_px = GR.inqdspsize()
@@ -657,6 +667,9 @@ function _update_min_padding!(sp::Subplot{GRBackend})
if sp[:yaxis][:guide] != ""
leftpad += 4mm
end
if sp[:colorbar_title] != ""
rightpad += 4mm
end
sp.minpad = Tuple(dpi * [leftpad, toppad, rightpad, bottompad])
end
@@ -1026,7 +1039,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
GR.setfillintstyle(GR.INTSTYLE_SOLID)
fr_from, fr_to = (is_2tuple(frng) ? frng : (y, frng))
for (i, rng) in enumerate(segments)
gr_set_fillcolor(get_fillcolor(series, i))
gr_set_fillcolor(get_fillcolor(series, clims, i))
fx = _cycle(x, vcat(rng, reverse(rng)))
fy = vcat(_cycle(fr_from,rng), _cycle(fr_to,reverse(rng)))
gr_set_transparency(get_fillalpha(series, i))
@@ -1037,7 +1050,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# draw the line(s)
if st in (:path, :straightline)
for (i, rng) in enumerate(segments)
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, i)) #, series[:linealpha])
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, clims, i)) #, series[:linealpha])
gr_set_transparency(get_linealpha(series, i))
arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none
gr_polyline(x[rng], y[rng]; arrowside = arrowside)
@@ -1103,10 +1116,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
GR.setspace(zmin, zmax, 0, 90)
grad = isa(series[:fillcolor], ColorGradient) ? series[:fillcolor] : cgrad()
colors = [plot_color(grad[clamp((zi-zmin) / (zmax-zmin), 0, 1)], series[:fillalpha]) for zi=z]
rgba = map(c -> UInt32( round(Int, alpha(c) * 255) << 24 +
round(Int, blue(c) * 255) << 16 +
round(Int, green(c) * 255) << 8 +
round(Int, red(c) * 255) ), colors)
rgba = map(c -> UInt32( round(UInt, alpha(c) * 255) << 24 +
round(UInt, blue(c) * 255) << 16 +
round(UInt, green(c) * 255) << 8 +
round(UInt, red(c) * 255) ), colors)
w, h = length(x), length(y)
GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba)
@@ -1117,7 +1130,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
lz = series[:line_z]
segments = iter_segments(series)
for (i, rng) in enumerate(segments)
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, i)) #, series[:linealpha])
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, clims, i)) #, series[:linealpha])
gr_set_transparency(get_linealpha(series, i))
GR.polyline3d(x[rng], y[rng], z[rng])
end
@@ -1189,12 +1202,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
xseg, yseg = x[rng], y[rng]
# draw the interior
gr_set_fill(get_fillcolor(series, i))
gr_set_fill(get_fillcolor(series, clims, i))
gr_set_transparency(get_fillalpha(series, i))
GR.fillarea(xseg, yseg)
# draw the shapes
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, i))
gr_set_line(get_linewidth(series, i), get_linestyle(series, i), get_linecolor(series, clims, i))
gr_set_transparency(get_linealpha(series, i))
GR.polyline(xseg, yseg)
end
@@ -1210,12 +1223,12 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
xmin, xmax = ignorenan_extrema(series[:x]); ymin, ymax = ignorenan_extrema(series[:y])
if eltype(z) <: Colors.AbstractGray
grey = round.(UInt8, float(z) * 255)
rgba = map(c -> UInt32( 0xff000000 + Int(c)<<16 + Int(c)<<8 + Int(c) ), grey)
rgba = map(c -> UInt32( 0xff000000 + UInt(c)<<16 + UInt(c)<<8 + UInt(c) ), grey)
else
rgba = map(c -> UInt32( round(Int, alpha(c) * 255) << 24 +
round(Int, blue(c) * 255) << 16 +
round(Int, green(c) * 255) << 8 +
round(Int, red(c) * 255) ), z)
rgba = map(c -> UInt32( round(UInt, alpha(c) * 255) << 24 +
round(UInt, blue(c) * 255) << 16 +
round(UInt, green(c) * 255) << 8 +
round(UInt, red(c) * 255) ), z)
end
GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba)
end
@@ -1227,16 +1240,18 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
gr_text(GR.wctondc(xi, yi)..., str)
end
# draw the colorbar
if cmap && st != :contour # special colorbar with steps is drawn for contours
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
gr_set_transparency(1)
gr_colorbar(sp, clims)
end
GR.restorestate()
end
# draw the colorbar
GR.savestate()
# special colorbar with steps is drawn for contours
if cmap && any(series[:seriestype] != :contour for series in series_list(sp))
gr_set_line(1, :solid, yaxis[:foreground_color_axis])
gr_set_transparency(1)
gr_colorbar(sp, clims)
end
GR.restorestate()
# add the legend
if sp[:legend] != :none
@@ -1284,10 +1299,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
for series in series_list(sp)
should_add_to_legend(series) || continue
st = series[:seriestype]
gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series)) #, series[:linealpha])
gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series, clims)) #, series[:linealpha])
if (st == :shape || series[:fillrange] != nothing) && series[:ribbon] == nothing
gr_set_fill(get_fillcolor(series)) #, series[:fillalpha])
gr_set_fill(get_fillcolor(series, clims)) #, series[:fillalpha])
l, r = xpos-0.07, xpos-0.01
b, t = ypos-0.4dy, ypos+0.4dy
x = [l, r, r, l, l]
@@ -1295,7 +1310,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
gr_set_transparency(get_fillalpha(series))
gr_polyline(x, y, GR.fillarea)
gr_set_transparency(get_linealpha(series))
gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series))
gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series, clims))
st == :shape && gr_polyline(x, y)
end
@@ -1309,7 +1324,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end
if series[:markershape] != :none
gr_draw_markers(series, xpos - .035, ypos, 6, nothing)
gr_draw_markers(series, xpos - .035, ypos, clims, 6)
end
if typeof(series[:label]) <: Array
+20 -17
View File
@@ -41,6 +41,7 @@ end
#==Useful constants
===============================================================================#
const _hdf5_nullable{T} = Union{T, Nothing}
const _hdf5_plotroot = "plot"
const _hdf5_dataroot = "data" #TODO: Eventually move data to different root (easier to locate)?
const _hdf5plot_datatypeid = "TYPE" #Attribute identifying type
@@ -129,7 +130,7 @@ if length(HDF5PLOT_MAP_TELEM2STR) < 1
"AXIS" => Axis,
"SURFACE" => Surface,
"SUBPLOT" => Subplot,
"NULLABLE" => Nullable,
"NULLABLE" => _hdf5_nullable,
)
merge!(HDF5PLOT_MAP_STR2TELEM, telem2str)
merge!(HDF5PLOT_MAP_TELEM2STR, Dict{Type, String}(v=>k for (k,v) in HDF5PLOT_MAP_STR2TELEM))
@@ -147,7 +148,7 @@ _hdf5_map_str2telem(v::Vector) = HDF5PLOT_MAP_STR2TELEM[v[1]]
function _hdf5_merge!(dest::Dict, src::Dict)
for (k, v) in src
if isa(v, Axis)
_hdf5_merge!(dest[k].d, v.d)
_hdf5_merge!(dest[k].plotattributes, v.plotattributes)
else
dest[k] = v
end
@@ -214,7 +215,7 @@ end
# ----------------------------------------------------------------
# Override this to update plot items (title, xlabel, etc), and add annotations (d[:annotations])
# Override this to update plot items (title, xlabel, etc), and add annotations (plotattributes[:annotations])
function _update_plot_object(plt::Plot{HDF5Backend})
#Do nothing
end
@@ -322,8 +323,8 @@ function _hdf5plot_gwrite(grp, k::String, v::Tuple)
end
#NOTE: _hdf5plot_overwritetype overwrites "Array" type with "Tuple".
end
function _hdf5plot_gwrite(grp, k::String, d::Dict)
# @warn("Cannot write dict: $k=$d")
function _hdf5plot_gwrite(grp, k::String, plotattributes::Dict)
# @warn("Cannot write dict: $k=$plotattributes")
end
function _hdf5plot_gwrite(grp, k::String, v::AbstractRange)
_hdf5plot_gwrite(grp, k, collect(v)) #For now
@@ -344,9 +345,10 @@ function _hdf5plot_gwritearray(grp, k::String, v::Array{T}) where T
vgrp = HDF5.g_create(grp, k)
_hdf5plot_writetype(vgrp, Array) #ANY
sz = size(v)
lidx = LinearIndices(sz)
for iter in eachindex(v)
coord = LinearIndices(sz, iter)
coord = lidx[iter]
elem = v[iter]
idxstr = join(coord, "_")
_hdf5plot_gwrite(vgrp, "v$idxstr", v[iter])
@@ -378,7 +380,7 @@ function _hdf5plot_gwrite(grp, k::String, v::HDF5PLOT_SIMPLESUBSTRUCT)
end
function _hdf5plot_gwrite(grp, k::String, v::Axis)
grp = HDF5.g_create(grp, k)
for (_k, _v) in v.d
for (_k, _v) in v.plotattributes
kstr = string(_k)
_hdf5plot_gwrite(grp, kstr, _v)
end
@@ -391,7 +393,7 @@ function _hdf5plot_gwrite(grp, k::String, v::Surface)
_hdf5plot_writetype(grp, Surface)
end
# #TODO: "Properly" support Nullable using _hdf5plot_writetype?
# function _hdf5plot_gwrite(grp, k::String, v::Nullable)
# function _hdf5plot_gwrite(grp, k::String, v::_hdf5_nullable)
# if isnull(v)
# _hdf5plot_gwrite(grp, k, nothing)
# else
@@ -410,8 +412,8 @@ function _hdf5plot_gwrite(grp, k::String, v::Subplot)
_hdf5plot_writetype(grp, Subplot)
return
end
function _hdf5plot_write(grp, d::Dict)
for (k, v) in d
function _hdf5plot_write(grp, plotattributes::Dict)
for (k, v) in plotattributes
kstr = string(k)
_hdf5plot_gwrite(grp, kstr, v)
end
@@ -429,7 +431,7 @@ function _hdf5plot_write(sp::Subplot{HDF5Backend}, subpath::String, f)
_hdf5plot_writecount(grp, length(sp.series_list))
for (i, series) in enumerate(sp.series_list)
grp = HDF5.g_create(f, _hdf5_plotelempath("$subpath/series_list/series$i"))
_hdf5plot_write(grp, series.d)
_hdf5plot_write(grp, series.plotattributes)
end
return
@@ -508,10 +510,11 @@ function _hdf5plot_read(grp, k::String, T::Type{Array}, dtid) #ANY
sz = _hdf5plot_read(grp, "dim")
if [0] == sz; return []; end
sz = tuple(sz...)
result = Array{Any}(sz)
result = Array{Any}(undef, sz)
lidx = LinearIndices(sz)
for iter in eachindex(result)
coord = LinearIndices(sz, iter)
coord = lidx[iter]
idxstr = join(coord, "_")
result[iter] = _hdf5plot_read(grp, "v$idxstr")
end
@@ -576,13 +579,13 @@ function _hdf5plot_read(grp, k::String)
return _hdf5plot_read(grp, k, T, dtid)
end
#Read in values in group to populate d:
function _hdf5plot_read(grp, d::Dict)
#Read in values in group to populate plotattributes:
function _hdf5plot_read(grp, plotattributes::Dict)
gnames = names(grp)
for k in gnames
try
v = _hdf5plot_read(grp, k)
d[Symbol(k)] = v
plotattributes[Symbol(k)] = v
catch e
@show e
@show grp
@@ -611,7 +614,7 @@ function _hdf5plot_read(sp::Subplot, subpath::String, f)
kwlist = KW()
_hdf5plot_read(grp, kwlist)
plot!(sp, kwlist[:x], kwlist[:y]) #Add data & create data structures
_hdf5_merge!(sp.series_list[end].d, kwlist)
_hdf5_merge!(sp.series_list[end].plotattributes, kwlist)
end
return
+1 -1
View File
@@ -457,7 +457,7 @@ end
# ----------------------------------------------------------------
# Override this to update plot items (title, xlabel, etc), and add annotations (d[:annotations])
# Override this to update plot items (title, xlabel, etc), and add annotations (plotattributes[:annotations])
function _update_plot_object(plt::Plot{InspectDRBackend})
mplot = _inspectdr_getmplot(plt.o)
if nothing == mplot; return; end
+40 -39
View File
@@ -23,7 +23,7 @@ const _pgfplots_attr = merge_with_base_supported([
:guide, :lims, :ticks, :scale, :flip, :rotation,
:tickfont, :guidefont, :legendfont,
:grid, :legend,
:colorbar,
:colorbar, :colorbar_title,
:fill_z, :line_z, :marker_z, :levels,
# :ribbon, :quiver, :arrow,
# :orientation,
@@ -133,9 +133,9 @@ pgf_thickness_scaling(plt::Plot) = plt[:thickness_scaling]
pgf_thickness_scaling(sp::Subplot) = pgf_thickness_scaling(sp.plt)
pgf_thickness_scaling(series) = pgf_thickness_scaling(series[:subplot])
function pgf_fillstyle(d, i = 1)
cstr,a = pgf_color(get_fillcolor(d, i))
fa = get_fillalpha(d, i)
function pgf_fillstyle(plotattributes, i = 1)
cstr,a = pgf_color(get_fillcolor(plotattributes, i))
fa = get_fillalpha(plotattributes, i)
if fa != nothing
a = fa
end
@@ -151,11 +151,11 @@ function pgf_linestyle(linewidth::Real, color, α = 1, linestyle = "solid")
$(get(_pgfplots_linestyles, linestyle, "solid"))"""
end
function pgf_linestyle(d, i = 1)
lw = pgf_thickness_scaling(d) * get_linewidth(d, i)
lc = get_linecolor(d, i)
la = get_linealpha(d, i)
ls = get_linestyle(d, i)
function pgf_linestyle(plotattributes, i = 1)
lw = pgf_thickness_scaling(plotattributes) * get_linewidth(plotattributes, i)
lc = get_linecolor(plotattributes, i)
la = get_linealpha(plotattributes, i)
ls = get_linestyle(plotattributes, i)
return pgf_linestyle(lw, lc, la, ls)
end
@@ -164,19 +164,19 @@ function pgf_font(fontsize, thickness_scaling = 1, font = "\\selectfont")
return string("{\\fontsize{", fs, " pt}{", 1.3fs, " pt}", font, "}")
end
function pgf_marker(d, i = 1)
shape = _cycle(d[:markershape], i)
cstr, a = pgf_color(plot_color(get_markercolor(d, i), get_markeralpha(d, i)))
cstr_stroke, a_stroke = pgf_color(plot_color(get_markerstrokecolor(d, i), get_markerstrokealpha(d, i)))
function pgf_marker(plotattributes, i = 1)
shape = _cycle(plotattributes[:markershape], i)
cstr, a = pgf_color(plot_color(get_markercolor(plotattributes, i), get_markeralpha(plotattributes, i)))
cstr_stroke, a_stroke = pgf_color(plot_color(get_markerstrokecolor(plotattributes, i), get_markerstrokealpha(plotattributes, i)))
"""
mark = $(get(_pgfplots_markers, shape, "*")),
mark size = $(pgf_thickness_scaling(d) * 0.5 * _cycle(d[:markersize], i)),
mark size = $(pgf_thickness_scaling(plotattributes) * 0.5 * _cycle(plotattributes[:markersize], i)),
mark options = {
color = $cstr_stroke, draw opacity = $a_stroke,
fill = $cstr, fill opacity = $a,
line width = $(pgf_thickness_scaling(d) * _cycle(d[:markerstrokewidth], i)),
line width = $(pgf_thickness_scaling(plotattributes) * _cycle(plotattributes[:markerstrokewidth], i)),
rotate = $(shape == :dtriangle ? 180 : 0),
$(get(_pgfplots_linestyles, _cycle(d[:markerstrokestyle], i), "solid"))
$(get(_pgfplots_linestyles, _cycle(plotattributes[:markerstrokestyle], i), "solid"))
}"""
end
@@ -197,24 +197,24 @@ end
# --------------------------------------------------------------------------------------
function pgf_series(sp::Subplot, series::Series)
d = series.d
st = d[:seriestype]
plotattributes = series.plotattributes
st = plotattributes[:seriestype]
series_collection = PGFPlots.Plot[]
# function args
args = if st == :contour
d[:z].surf, d[:x], d[:y]
plotattributes[:z].surf, plotattributes[:x], plotattributes[:y]
elseif is3d(st)
d[:x], d[:y], d[:z]
plotattributes[:x], plotattributes[:y], plotattributes[:z]
elseif st == :straightline
straightline_data(series)
elseif st == :shape
shape_data(series)
elseif ispolar(sp)
theta, r = filter_radial_data(d[:x], d[:y], axis_limits(sp[:yaxis]))
theta, r = filter_radial_data(plotattributes[:x], plotattributes[:y], axis_limits(sp[:yaxis]))
rad2deg.(theta), r
else
d[:x], d[:y]
plotattributes[:x], plotattributes[:y]
end
# PGFPlots can't handle non-Vector?
@@ -227,8 +227,8 @@ function pgf_series(sp::Subplot, series::Series)
if st in (:contour, :histogram2d)
style = []
kw = KW()
push!(style, pgf_linestyle(d))
push!(style, pgf_marker(d))
push!(style, pgf_linestyle(plotattributes))
push!(style, pgf_marker(plotattributes))
push!(style, "forget plot")
kw[:style] = join(style, ',')
@@ -247,21 +247,21 @@ function pgf_series(sp::Subplot, series::Series)
for (i, rng) in enumerate(segments)
style = []
kw = KW()
push!(style, pgf_linestyle(d, i))
push!(style, pgf_marker(d, i))
push!(style, pgf_linestyle(plotattributes, i))
push!(style, pgf_marker(plotattributes, i))
if st == :shape
push!(style, pgf_fillstyle(d, i))
push!(style, pgf_fillstyle(plotattributes, i))
end
# add to legend?
if i == 1 && sp[:legend] != :none && should_add_to_legend(series)
if d[:fillrange] != nothing
if plotattributes[:fillrange] != nothing
push!(style, "forget plot")
push!(series_collection, pgf_fill_legend_hack(d, args))
push!(series_collection, pgf_fill_legend_hack(plotattributes, args))
else
kw[:legendentry] = d[:label]
if st == :shape # || d[:fillrange] != nothing
kw[:legendentry] = plotattributes[:label]
if st == :shape # || plotattributes[:fillrange] != nothing
push!(style, "area legend")
end
end
@@ -328,16 +328,16 @@ function pgf_fillrange_args(fillrange, x, y, z)
return x_fill, y_fill, z_fill
end
function pgf_fill_legend_hack(d, args)
function pgf_fill_legend_hack(plotattributes, args)
style = []
kw = KW()
push!(style, pgf_linestyle(d, 1))
push!(style, pgf_marker(d, 1))
push!(style, pgf_fillstyle(d, 1))
push!(style, pgf_linestyle(plotattributes, 1))
push!(style, pgf_marker(plotattributes, 1))
push!(style, pgf_fillstyle(plotattributes, 1))
push!(style, "area legend")
kw[:legendentry] = d[:label]
kw[:legendentry] = plotattributes[:label]
kw[:style] = join(style, ',')
st = d[:seriestype]
st = plotattributes[:seriestype]
func = if st == :path3d
PGFPlots.Linear3
elseif st == :scatter
@@ -535,8 +535,8 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend})
# colormap this should not cause any problem.
for series in series_list(sp)
for col in (:markercolor, :fillcolor, :linecolor)
if typeof(series.d[col]) == ColorGradient
push!(style,"colormap={plots}{$(pgf_colormap(series.d[col]))}")
if typeof(series.plotattributes[col]) == ColorGradient
push!(style,"colormap={plots}{$(pgf_colormap(series.plotattributes[col]))}")
if sp[:colorbar] == :none
kw[:colorbar] = "false"
@@ -550,6 +550,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend})
end
@label colorbar_end
push!(style, "colorbar style={title=$(sp[:colorbar_title])}")
o = axisf(; style = join(style, ","), kw...)
# add the series object to the PGFPlots.Axis
+138 -136
View File
@@ -149,7 +149,7 @@ function plotly_annotation_dict(x, y, ptxt::PlotText; xref="paper", yref="paper"
))
end
# function get_annotation_dict_for_arrow(d::KW, xyprev::Tuple, xy::Tuple, a::Arrow)
# function get_annotation_dict_for_arrow(plotattributes::KW, xyprev::Tuple, xy::Tuple, a::Arrow)
# xdiff = xyprev[1] - xy[1]
# ydiff = xyprev[2] - xy[2]
# dist = sqrt(xdiff^2 + ydiff^2)
@@ -163,7 +163,7 @@ end
# # :ay => -40,
# :ax => 10xdiff / dist,
# :ay => -10ydiff / dist,
# :arrowcolor => rgba_string(d[:linecolor]),
# :arrowcolor => rgba_string(plotattributes[:linecolor]),
# :xref => "x",
# :yref => "y",
# :arrowsize => 10a.headwidth,
@@ -306,14 +306,14 @@ function plotly_polaraxis(axis::Axis)
end
function plotly_layout(plt::Plot)
d_out = KW()
plotattributes_out = KW()
w, h = plt[:size]
d_out[:width], d_out[:height] = w, h
d_out[:paper_bgcolor] = rgba_string(plt[:background_color_outside])
d_out[:margin] = KW(:l=>0, :b=>20, :r=>0, :t=>20)
plotattributes_out[:width], plotattributes_out[:height] = w, h
plotattributes_out[:paper_bgcolor] = rgba_string(plt[:background_color_outside])
plotattributes_out[:margin] = KW(:l=>0, :b=>20, :r=>0, :t=>20)
d_out[:annotations] = KW[]
plotattributes_out[:annotations] = KW[]
multiple_subplots = length(plt.subplots) > 1
@@ -334,10 +334,10 @@ function plotly_layout(plt::Plot)
end
titlex, titley = xy_mm_to_pcts(xmm, top(bbox(sp)), w*px, h*px)
title_font = font(titlefont(sp), :top)
push!(d_out[:annotations], plotly_annotation_dict(titlex, titley, text(sp[:title], title_font)))
push!(plotattributes_out[:annotations], plotly_annotation_dict(titlex, titley, text(sp[:title], title_font)))
end
d_out[:plot_bgcolor] = rgba_string(sp[:background_color_inside])
plotattributes_out[:plot_bgcolor] = rgba_string(sp[:background_color_inside])
# set to supported framestyle
sp[:framestyle] = _plotly_framestyle(sp[:framestyle])
@@ -346,7 +346,7 @@ function plotly_layout(plt::Plot)
if is3d(sp)
azim = sp[:camera][1] - 90 #convert azimuthal to match GR behaviour
theta = 90 - sp[:camera][2] #spherical coordinate angle from z axis
d_out[:scene] = KW(
plotattributes_out[:scene] = KW(
Symbol("xaxis$(spidx)") => plotly_axis(plt, sp[:xaxis], sp),
Symbol("yaxis$(spidx)") => plotly_axis(plt, sp[:yaxis], sp),
Symbol("zaxis$(spidx)") => plotly_axis(plt, sp[:zaxis], sp),
@@ -361,19 +361,19 @@ function plotly_layout(plt::Plot)
),
)
elseif ispolar(sp)
d_out[Symbol("angularaxis$(spidx)")] = plotly_polaraxis(sp[:xaxis])
d_out[Symbol("radialaxis$(spidx)")] = plotly_polaraxis(sp[:yaxis])
plotattributes_out[Symbol("angularaxis$(spidx)")] = plotly_polaraxis(sp[:xaxis])
plotattributes_out[Symbol("radialaxis$(spidx)")] = plotly_polaraxis(sp[:yaxis])
else
d_out[Symbol("xaxis$(x_idx)")] = plotly_axis(plt, sp[:xaxis], sp)
plotattributes_out[Symbol("xaxis$(x_idx)")] = plotly_axis(plt, sp[:xaxis], sp)
# don't allow yaxis to be reupdated/reanchored in a linked subplot
spidx == y_idx ? d_out[Symbol("yaxis$(y_idx)")] = plotly_axis(plt, sp[:yaxis], sp) : nothing
spidx == y_idx ? plotattributes_out[Symbol("yaxis$(y_idx)")] = plotly_axis(plt, sp[:yaxis], sp) : nothing
end
# legend
d_out[:showlegend] = sp[:legend] != :none
plotattributes_out[:showlegend] = sp[:legend] != :none
xpos,ypos = plotly_legend_pos(sp[:legend])
if sp[:legend] != :none
d_out[:legend] = KW(
plotattributes_out[:legend] = KW(
:bgcolor => rgba_string(sp[:background_color_legend]),
:bordercolor => rgba_string(sp[:foreground_color_legend]),
:font => plotly_font(legendfont(sp)),
@@ -385,13 +385,13 @@ function plotly_layout(plt::Plot)
# annotations
for ann in sp[:annotations]
append!(d_out[:annotations], KW[plotly_annotation_dict(locate_annotation(sp, ann...)...; xref = "x$(x_idx)", yref = "y$(y_idx)")])
append!(plotattributes_out[:annotations], KW[plotly_annotation_dict(locate_annotation(sp, ann...)...; xref = "x$(x_idx)", yref = "y$(y_idx)")])
end
# series_annotations
for series in series_list(sp)
anns = series[:series_annotations]
for (xi,yi,str,fnt) in EachAnn(anns, series[:x], series[:y])
push!(d_out[:annotations], plotly_annotation_dict(
push!(plotattributes_out[:annotations], plotly_annotation_dict(
xi,
yi,
PlotText(str,fnt); xref = "x$(x_idx)", yref = "y$(y_idx)")
@@ -404,24 +404,24 @@ function plotly_layout(plt::Plot)
# a = sargs[:arrow]
# if sargs[:seriestype] in (:path, :line) && typeof(a) <: Arrow
# add_arrows(sargs[:x], sargs[:y]) do xyprev, xy
# push!(d_out[:annotations], get_annotation_dict_for_arrow(sargs, xyprev, xy, a))
# push!(plotattributes_out[:annotations], get_annotation_dict_for_arrow(sargs, xyprev, xy, a))
# end
# end
# end
if ispolar(sp)
d_out[:direction] = "counterclockwise"
plotattributes_out[:direction] = "counterclockwise"
end
d_out
plotattributes_out
end
# turn off hover if nothing's using it
if all(series -> series.d[:hover] in (false,:none), plt.series_list)
d_out[:hovermode] = "none"
if all(series -> series.plotattributes[:hover] in (false,:none), plt.series_list)
plotattributes_out[:hovermode] = "none"
end
d_out
plotattributes_out
end
function plotly_layout_json(plt::Plot)
@@ -527,21 +527,24 @@ end
as_gradient(grad::ColorGradient, α) = grad
as_gradient(grad, α) = cgrad(alpha = α)
# get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict)
# get a dictionary representing the series params (plotattributes is the Plots-dict, plotattributes_out is the Plotly-dict)
function plotly_series(plt::Plot, series::Series)
st = series[:seriestype]
if st == :shape
return plotly_series_shapes(plt, series)
end
sp = series[:subplot]
d_out = KW()
clims = get_clims(sp)
if st == :shape
return plotly_series_shapes(plt, series, clims)
end
plotattributes_out = KW()
# these are the axes that the series should be mapped to
x_idx, y_idx = plotly_link_indicies(plt, sp)
d_out[:xaxis] = "x$(x_idx)"
d_out[:yaxis] = "y$(y_idx)"
d_out[:showlegend] = should_add_to_legend(series)
plotattributes_out[:xaxis] = "x$(x_idx)"
plotattributes_out[:yaxis] = "y$(y_idx)"
plotattributes_out[:showlegend] = should_add_to_legend(series)
if st == :straightline
x, y = straightline_data(series)
@@ -554,7 +557,7 @@ function plotly_series(plt::Plot, series::Series)
for (letter, data) in zip((:x, :y, :z), (x, y, z))
)
d_out[:name] = series[:label]
plotattributes_out[:name] = series[:label]
isscatter = st in (:scatter, :scatter3d, :scattergl)
hasmarker = isscatter || series[:markershape] != :none
@@ -562,60 +565,59 @@ function plotly_series(plt::Plot, series::Series)
hasfillrange = st in (:path, :scatter, :scattergl, :straightline) &&
(isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple))
d_out[:colorbar] = KW(:title => sp[:colorbar_title])
plotattributes_out[:colorbar] = KW(:title => sp[:colorbar_title])
clims = sp[:clims]
if is_2tuple(clims)
d_out[:zmin], d_out[:zmax] = clims
plotattributes_out[:zmin], plotattributes_out[:zmax] = clims
end
# set the "type"
if st in (:path, :scatter, :scattergl, :straightline, :path3d, :scatter3d)
return plotly_series_segments(series, d_out, x, y, z)
return plotly_series_segments(series, plotattributes_out, x, y, z, clims)
elseif st == :heatmap
x = heatmap_edges(x, sp[:xaxis][:scale])
y = heatmap_edges(y, sp[:yaxis][:scale])
d_out[:type] = "heatmap"
d_out[:x], d_out[:y], d_out[:z] = x, y, z
d_out[:colorscale] = plotly_colorscale(series[:fillcolor], series[:fillalpha])
d_out[:showscale] = hascolorbar(sp)
plotattributes_out[:type] = "heatmap"
plotattributes_out[:x], plotattributes_out[:y], plotattributes_out[:z] = x, y, z
plotattributes_out[:colorscale] = plotly_colorscale(series[:fillcolor], series[:fillalpha])
plotattributes_out[:showscale] = hascolorbar(sp)
elseif st == :contour
d_out[:type] = "contour"
d_out[:x], d_out[:y], d_out[:z] = x, y, z
# d_out[:showscale] = series[:colorbar] != :none
d_out[:ncontours] = series[:levels]
d_out[:contours] = KW(:coloring => series[:fillrange] != nothing ? "fill" : "lines", :showlabels => series[:contour_labels] == true)
d_out[:colorscale] = plotly_colorscale(series[:linecolor], series[:linealpha])
d_out[:showscale] = hascolorbar(sp)
plotattributes_out[:type] = "contour"
plotattributes_out[:x], plotattributes_out[:y], plotattributes_out[:z] = x, y, z
# plotattributes_out[:showscale] = series[:colorbar] != :none
plotattributes_out[:ncontours] = series[:levels]
plotattributes_out[:contours] = KW(:coloring => series[:fillrange] != nothing ? "fill" : "lines", :showlabels => series[:contour_labels] == true)
plotattributes_out[:colorscale] = plotly_colorscale(series[:linecolor], series[:linealpha])
plotattributes_out[:showscale] = hascolorbar(sp)
elseif st in (:surface, :wireframe)
d_out[:type] = "surface"
d_out[:x], d_out[:y], d_out[:z] = x, y, z
plotattributes_out[:type] = "surface"
plotattributes_out[:x], plotattributes_out[:y], plotattributes_out[:z] = x, y, z
if st == :wireframe
d_out[:hidesurface] = true
plotattributes_out[:hidesurface] = true
wirelines = KW(
:show => true,
:color => rgba_string(plot_color(series[:linecolor], series[:linealpha])),
:highlightwidth => series[:linewidth],
)
d_out[:contours] = KW(:x => wirelines, :y => wirelines, :z => wirelines)
d_out[:showscale] = false
plotattributes_out[:contours] = KW(:x => wirelines, :y => wirelines, :z => wirelines)
plotattributes_out[:showscale] = false
else
d_out[:colorscale] = plotly_colorscale(series[:fillcolor], series[:fillalpha])
d_out[:opacity] = series[:fillalpha]
plotattributes_out[:colorscale] = plotly_colorscale(series[:fillcolor], series[:fillalpha])
plotattributes_out[:opacity] = series[:fillalpha]
if series[:fill_z] != nothing
d_out[:surfacecolor] = plotly_surface_data(series, series[:fill_z])
plotattributes_out[:surfacecolor] = plotly_surface_data(series, series[:fill_z])
end
d_out[:showscale] = hascolorbar(sp)
plotattributes_out[:showscale] = hascolorbar(sp)
end
elseif st == :pie
d_out[:type] = "pie"
d_out[:labels] = pie_labels(sp, series)
d_out[:values] = y
d_out[:hoverinfo] = "label+percent+name"
plotattributes_out[:type] = "pie"
plotattributes_out[:labels] = pie_labels(sp, series)
plotattributes_out[:values] = y
plotattributes_out[:hoverinfo] = "label+percent+name"
else
@warn("Plotly: seriestype $st isn't supported.")
@@ -625,7 +627,7 @@ function plotly_series(plt::Plot, series::Series)
# add "marker"
if hasmarker
inds = eachindex(x)
d_out[:marker] = KW(
plotattributes_out[:marker] = KW(
:symbol => get(_plotly_markers, series[:markershape], string(series[:markershape])),
# :opacity => series[:markeralpha],
:size => 2 * _cycle(series[:markersize], inds),
@@ -637,22 +639,22 @@ function plotly_series(plt::Plot, series::Series)
)
end
plotly_polar!(d_out, series)
plotly_hover!(d_out, series[:hover])
plotly_polar!(plotattributes_out, series)
plotly_hover!(plotattributes_out, series[:hover])
return [d_out]
return [plotattributes_out]
end
function plotly_series_shapes(plt::Plot, series::Series)
function plotly_series_shapes(plt::Plot, series::Series, clims)
segments = iter_segments(series)
d_outs = Vector{KW}(length(segments))
plotattributes_outs = Vector{KW}(undef, length(segments))
# TODO: create a d_out for each polygon
# TODO: create a plotattributes_out for each polygon
# x, y = series[:x], series[:y]
# these are the axes that the series should be mapped to
x_idx, y_idx = plotly_link_indicies(plt, series[:subplot])
d_base = KW(
plotattributes_base = KW(
:xaxis => "x$(x_idx)",
:yaxis => "y$(y_idx)",
:name => series[:label],
@@ -667,37 +669,37 @@ function plotly_series_shapes(plt::Plot, series::Series)
length(rng) < 2 && continue
# to draw polygons, we actually draw lines with fill
d_out = merge(d_base, KW(
plotattributes_out = merge(plotattributes_base, KW(
:type => "scatter",
:mode => "lines",
:x => vcat(x[rng], x[rng[1]]),
:y => vcat(y[rng], y[rng[1]]),
:fill => "tozeroy",
:fillcolor => rgba_string(plot_color(get_fillcolor(series, i), get_fillalpha(series, i))),
:fillcolor => rgba_string(plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i))),
))
if series[:markerstrokewidth] > 0
d_out[:line] = KW(
:color => rgba_string(plot_color(get_linecolor(series, i), get_linealpha(series, i))),
plotattributes_out[:line] = KW(
:color => rgba_string(plot_color(get_linecolor(series, clims, i), get_linealpha(series, i))),
:width => get_linewidth(series, i),
:dash => string(get_linestyle(series, i)),
)
end
d_out[:showlegend] = i==1 ? should_add_to_legend(series) : false
plotly_polar!(d_out, series)
plotly_hover!(d_out, _cycle(series[:hover], i))
d_outs[i] = d_out
plotattributes_out[:showlegend] = i==1 ? should_add_to_legend(series) : false
plotly_polar!(plotattributes_out, series)
plotly_hover!(plotattributes_out, _cycle(series[:hover], i))
plotattributes_outs[i] = plotattributes_out
end
if series[:fill_z] != nothing
push!(d_outs, plotly_colorbar_hack(series, d_base, :fill))
push!(plotattributes_outs, plotly_colorbar_hack(series, plotattributes_base, :fill))
elseif series[:line_z] != nothing
push!(d_outs, plotly_colorbar_hack(series, d_base, :line))
push!(plotattributes_outs, plotly_colorbar_hack(series, plotattributes_base, :line))
elseif series[:marker_z] != nothing
push!(d_outs, plotly_colorbar_hack(series, d_base, :marker))
push!(plotattributes_outs, plotly_colorbar_hack(series, plotattributes_base, :marker))
end
d_outs
plotattributes_outs
end
function plotly_series_segments(series::Series, d_base::KW, x, y, z)
function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z, clims)
st = series[:seriestype]
sp = series[:subplot]
isscatter = st in (:scatter, :scatter3d, :scattergl)
@@ -707,51 +709,51 @@ function plotly_series_segments(series::Series, d_base::KW, x, y, z)
(isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple))
segments = iter_segments(series)
d_outs = Vector{KW}((hasfillrange ? 2 : 1 ) * length(segments))
plotattributes_outs = Vector{KW}(undef, (hasfillrange ? 2 : 1 ) * length(segments))
for (i,rng) in enumerate(segments)
!isscatter && length(rng) < 2 && continue
d_out = deepcopy(d_base)
d_out[:showlegend] = i==1 ? should_add_to_legend(series) : false
d_out[:legendgroup] = series[:label]
plotattributes_out = deepcopy(plotattributes_base)
plotattributes_out[:showlegend] = i==1 ? should_add_to_legend(series) : false
plotattributes_out[:legendgroup] = series[:label]
# set the type
if st in (:path, :scatter, :scattergl, :straightline)
d_out[:type] = st==:scattergl ? "scattergl" : "scatter"
d_out[:mode] = if hasmarker
plotattributes_out[:type] = st==:scattergl ? "scattergl" : "scatter"
plotattributes_out[:mode] = if hasmarker
hasline ? "lines+markers" : "markers"
else
hasline ? "lines" : "none"
end
if series[:fillrange] == true || series[:fillrange] == 0 || isa(series[:fillrange], Tuple)
d_out[:fill] = "tozeroy"
d_out[:fillcolor] = rgba_string(plot_color(get_fillcolor(series, i), get_fillalpha(series, i)))
plotattributes_out[:fill] = "tozeroy"
plotattributes_out[:fillcolor] = rgba_string(plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)))
elseif typeof(series[:fillrange]) <: Union{AbstractVector{<:Real}, Real}
d_out[:fill] = "tonexty"
d_out[:fillcolor] = rgba_string(plot_color(get_fillcolor(series, i), get_fillalpha(series, i)))
plotattributes_out[:fill] = "tonexty"
plotattributes_out[:fillcolor] = rgba_string(plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)))
elseif !(series[:fillrange] in (false, nothing))
@warn("fillrange ignored... plotly only supports filling to zero and to a vector of values. fillrange: $(series[:fillrange])")
end
d_out[:x], d_out[:y] = x[rng], y[rng]
plotattributes_out[:x], plotattributes_out[:y] = x[rng], y[rng]
elseif st in (:path3d, :scatter3d)
d_out[:type] = "scatter3d"
d_out[:mode] = if hasmarker
plotattributes_out[:type] = "scatter3d"
plotattributes_out[:mode] = if hasmarker
hasline ? "lines+markers" : "markers"
else
hasline ? "lines" : "none"
end
d_out[:x], d_out[:y], d_out[:z] = x[rng], y[rng], z[rng]
plotattributes_out[:x], plotattributes_out[:y], plotattributes_out[:z] = x[rng], y[rng], z[rng]
end
# add "marker"
if hasmarker
d_out[:marker] = KW(
plotattributes_out[:marker] = KW(
:symbol => get(_plotly_markers, _cycle(series[:markershape], i), string(_cycle(series[:markershape], i))),
# :opacity => series[:markeralpha],
:size => 2 * _cycle(series[:markersize], i),
:color => rgba_string(plot_color(get_markercolor(series, i), get_markeralpha(series, i))),
:color => rgba_string(plot_color(get_markercolor(series, clims, i), get_markeralpha(series, i))),
:line => KW(
:color => rgba_string(plot_color(get_markerstrokecolor(series, i), get_markerstrokealpha(series, i))),
:width => _cycle(series[:markerstrokewidth], i),
@@ -761,8 +763,8 @@ function plotly_series_segments(series::Series, d_base::KW, x, y, z)
# add "line"
if hasline
d_out[:line] = KW(
:color => rgba_string(plot_color(get_linecolor(series, i), get_linealpha(series, i))),
plotattributes_out[:line] = KW(
:color => rgba_string(plot_color(get_linecolor(series, clims, i), get_linealpha(series, i))),
:width => get_linewidth(series, i),
:shape => if st == :steppre
"vh"
@@ -775,14 +777,14 @@ function plotly_series_segments(series::Series, d_base::KW, x, y, z)
)
end
plotly_polar!(d_out, series)
plotly_hover!(d_out, _cycle(series[:hover], rng))
plotly_polar!(plotattributes_out, series)
plotly_hover!(plotattributes_out, _cycle(series[:hover], rng))
if hasfillrange
# if hasfillrange is true, return two dictionaries (one for original
# series, one for series being filled to) instead of one
d_out_fillrange = deepcopy(d_out)
d_out_fillrange[:showlegend] = false
plotattributes_out_fillrange = deepcopy(plotattributes_out)
plotattributes_out_fillrange[:showlegend] = false
# if fillrange is provided as real or tuple of real, expand to array
if typeof(series[:fillrange]) <: Real
series[:fillrange] = fill(series[:fillrange], length(rng))
@@ -792,49 +794,49 @@ function plotly_series_segments(series::Series, d_base::KW, x, y, z)
series[:fillrange] = (f1, f2)
end
if isa(series[:fillrange], AbstractVector)
d_out_fillrange[:y] = series[:fillrange][rng]
delete!(d_out_fillrange, :fill)
delete!(d_out_fillrange, :fillcolor)
plotattributes_out_fillrange[:y] = series[:fillrange][rng]
delete!(plotattributes_out_fillrange, :fill)
delete!(plotattributes_out_fillrange, :fillcolor)
else
# if fillrange is a tuple with upper and lower limit, d_out_fillrange
# if fillrange is a tuple with upper and lower limit, plotattributes_out_fillrange
# is the series that will do the filling
fillrng = Tuple(series[:fillrange][i][rng] for i in 1:2)
d_out_fillrange[:x], d_out_fillrange[:y] = concatenate_fillrange(x[rng], fillrng)
d_out_fillrange[:line][:width] = 0
delete!(d_out, :fill)
delete!(d_out, :fillcolor)
plotattributes_out_fillrange[:x], plotattributes_out_fillrange[:y] = concatenate_fillrange(x[rng], fillrng)
plotattributes_out_fillrange[:line][:width] = 0
delete!(plotattributes_out, :fill)
delete!(plotattributes_out, :fillcolor)
end
d_outs[(2 * i - 1):(2 * i)] = [d_out_fillrange, d_out]
plotattributes_outs[(2 * i - 1):(2 * i)] = [plotattributes_out_fillrange, plotattributes_out]
else
d_outs[i] = d_out
plotattributes_outs[i] = plotattributes_out
end
end
if series[:line_z] != nothing
push!(d_outs, plotly_colorbar_hack(series, d_base, :line))
push!(plotattributes_outs, plotly_colorbar_hack(series, plotattributes_base, :line))
elseif series[:fill_z] != nothing
push!(d_outs, plotly_colorbar_hack(series, d_base, :fill))
push!(plotattributes_outs, plotly_colorbar_hack(series, plotattributes_base, :fill))
elseif series[:marker_z] != nothing
push!(d_outs, plotly_colorbar_hack(series, d_base, :marker))
push!(plotattributes_outs, plotly_colorbar_hack(series, plotattributes_base, :marker))
end
d_outs
plotattributes_outs
end
function plotly_colorbar_hack(series::Series, d_base::KW, sym::Symbol)
d_out = deepcopy(d_base)
function plotly_colorbar_hack(series::Series, plotattributes_base::KW, sym::Symbol)
plotattributes_out = deepcopy(plotattributes_base)
cmin, cmax = get_clims(series[:subplot])
d_out[:showlegend] = false
d_out[:type] = is3d(series) ? :scatter3d : :scatter
d_out[:hoverinfo] = :none
d_out[:mode] = :markers
d_out[:x], d_out[:y] = [series[:x][1]], [series[:y][1]]
plotattributes_out[:showlegend] = false
plotattributes_out[:type] = is3d(series) ? :scatter3d : :scatter
plotattributes_out[:hoverinfo] = :none
plotattributes_out[:mode] = :markers
plotattributes_out[:x], plotattributes_out[:y] = [series[:x][1]], [series[:y][1]]
if is3d(series)
d_out[:z] = [series[:z][1]]
plotattributes_out[:z] = [series[:z][1]]
end
# zrange = zmax == zmin ? 1 : zmax - zmin # if all marker_z values are the same, plot all markers same color (avoids division by zero in next line)
d_out[:marker] = KW(
plotattributes_out[:marker] = KW(
:size => 0,
:opacity => 0,
:color => [0.5],
@@ -843,26 +845,26 @@ function plotly_colorbar_hack(series::Series, d_base::KW, sym::Symbol)
:colorscale => plotly_colorscale(series[Symbol("$(sym)color")], 1),
:showscale => hascolorbar(series[:subplot]),
)
return d_out
return plotattributes_out
end
function plotly_polar!(d_out::KW, series::Series)
function plotly_polar!(plotattributes_out::KW, series::Series)
# convert polar plots x/y to theta/radius
if ispolar(series[:subplot])
theta, r = filter_radial_data(pop!(d_out, :x), pop!(d_out, :y), axis_limits(series[:subplot][:yaxis]))
d_out[:t] = rad2deg.(theta)
d_out[:r] = r
theta, r = filter_radial_data(pop!(plotattributes_out, :x), pop!(plotattributes_out, :y), axis_limits(series[:subplot][:yaxis]))
plotattributes_out[:t] = rad2deg.(theta)
plotattributes_out[:r] = r
end
end
function plotly_hover!(d_out::KW, hover)
function plotly_hover!(plotattributes_out::KW, hover)
# hover text
if hover in (:none, false)
d_out[:hoverinfo] = "none"
plotattributes_out[:hoverinfo] = "none"
elseif hover != nothing
d_out[:hoverinfo] = "text"
d_out[:text] = hover
plotattributes_out[:hoverinfo] = "text"
plotattributes_out[:text] = hover
end
end
+2 -2
View File
@@ -31,14 +31,14 @@ end
function _series_updated(plt::Plot{PlotlyJSBackend}, series::Series)
xsym, ysym = (ispolar(series) ? (:t,:r) : (:x,:y))
kw = KW(xsym => (series.d[:x],), ysym => (series.d[:y],))
kw = KW(xsym => (series.plotattributes[:x],), ysym => (series.plotattributes[:y],))
z = series[:z]
if z != nothing
kw[:z] = (isa(z,Surface) ? transpose_z(series, series[:z].surf, false) : z,)
end
PlotlyJS.restyle!(
plt.o,
findfirst(plt.series_list, series),
findfirst(isequal(series), plt.series_list),
kw
)
end
+32 -36
View File
@@ -236,16 +236,17 @@ function add_pyfixedformatter(cbar, vals::AVec)
cbar[:update_ticks]()
end
function labelfunc(scale::Symbol, backend::PyPlotBackend)
if scale == :log10
x -> latexstring("10^{$x}")
elseif scale == :log2
x -> latexstring("2^{$x}")
elseif scale == :ln
x -> latexstring("e^{$x}")
else
string
@require LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" begin
function labelfunc(scale::Symbol, backend::PyPlotBackend)
if scale == :log10
x -> LaTeXStrings.latexstring("10^{$x}")
elseif scale == :log2
x -> LaTeXStrings.latexstring("2^{$x}")
elseif scale == :ln
x -> LaTeXStrings.latexstring("e^{$x}")
else
string
end
end
end
@@ -262,7 +263,7 @@ end
function fix_xy_lengths!(plt::Plot{PyPlotBackend}, series::Series)
x, y = series[:x], series[:y]
nx, ny = length(x), length(y)
if !isa(get(series.d, :z, nothing), Surface) && nx != ny
if !isa(get(series.plotattributes, :z, nothing), Surface) && nx != ny
if nx < ny
series[:x] = Float64[x[mod1(i,nx)] for i=1:ny]
else
@@ -298,7 +299,7 @@ py_fillcolormap(series::Series) = py_colormap(series[:fillcolor])
# getAxis(sp::Subplot) = sp.o
# function getAxis(plt::Plot{PyPlotBackend}, series::Series)
# sp = get_subplot(plt, get(series.d, :subplot, 1))
# sp = get_subplot(plt, get(series.plotattributes, :subplot, 1))
# getAxis(sp)
# end
@@ -411,12 +412,12 @@ end
# ---------------------------------------------------------------------------
# function _series_added(pkg::PyPlotBackend, plt::Plot, d::KW)
# function _series_added(pkg::PyPlotBackend, plt::Plot, plotattributes::KW)
# TODO: change this to accept Subplot??
# function _series_added(plt::Plot{PyPlotBackend}, series::Series)
function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# d = series.d
# plotattributes = series.plotattributes
st = series[:seriestype]
sp = series[:subplot]
ax = sp.o
@@ -435,12 +436,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
# handle zcolor and get c/cmap
needs_colorbar = hascolorbar(sp)
extrakw = if needs_colorbar || is_2tuple(sp[:clims])
vmin, vmax = get_clims(sp)
KW(:vmin => vmin, :vmax => vmax)
else
KW()
end
vmin, vmax = clims = get_clims(sp)
# Dict to store extra kwargs
extrakw = KW(:vmin => vmin, :vmax => vmax)
# holds references to any python object representing the matplotlib series
handles = []
@@ -501,7 +500,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
handle = ax[:plot]((arg[rng] for arg in xyargs)...;
label = i == 1 ? series[:label] : "",
zorder = series[:series_plotindex],
color = py_color(get_linecolor(series, i), get_linealpha(series, i)),
color = py_color(get_linecolor(series, clims, i), get_linealpha(series, i)),
linewidth = py_thickness_scale(plt, get_linewidth(series, i)),
linestyle = py_linestyle(st, get_linestyle(series, i)),
solid_capstyle = "round",
@@ -543,7 +542,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
:scatter3d, :steppre, :steppost,
:bar)
markercolor = if any(typeof(series[arg]) <: AVec for arg in (:markercolor, :markeralpha)) || series[:marker_z] != nothing
py_color(plot_color.(get_markercolor.(series, eachindex(x)), get_markeralpha.(series, eachindex(x))))
# py_color(plot_color.(get_markercolor.(series, clims, eachindex(x)), get_markeralpha.(series, eachindex(x))))
[py_color(plot_color(get_markercolor(series, clims, i), get_markeralpha(series, i))) for i in eachindex(x)]
else
py_color(plot_color(series[:markercolor], series[:markeralpha]))
end
@@ -691,11 +691,6 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
elseif typeof(z) <: AbstractVector
# tri-surface plot (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots)
clims = sp[:clims]
if is_2tuple(clims)
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
end
handle = ax[:plot_trisurf](x, y, z;
label = series[:label],
zorder = series[:series_plotindex],
@@ -766,8 +761,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
path;
label = series[:label],
zorder = series[:series_plotindex],
edgecolor = py_color(get_linecolor(series, i), get_linealpha(series, i)),
facecolor = py_color(get_fillcolor(series, i), get_fillalpha(series, i)),
edgecolor = py_color(get_linecolor(series, clims, i), get_linealpha(series, i)),
facecolor = py_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)),
linewidth = py_thickness_scale(plt, get_linewidth(series, i)),
linestyle = py_linestyle(st, get_linestyle(series, i)),
fill = true
@@ -816,7 +811,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
handle = ax[f](args..., trues(n), false, py_fillstepstyle(st);
zorder = series[:series_plotindex],
facecolor = py_color(get_fillcolor(series, i), get_fillalpha(series, i)),
facecolor = py_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)),
linewidths = 0
)
push!(handles, handle)
@@ -867,7 +862,7 @@ function py_compute_axis_minval(axis::Axis)
sps = axis.sps
for sp in sps
for series in series_list(sp)
v = series.d[axis[:letter]]
v = series.plotattributes[axis[:letter]]
if !isempty(v)
minval = NaNMath.min(minval, ignorenan_minimum(abs.(v)))
end
@@ -1071,7 +1066,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
axis[:ticks] != :native ? py_set_ticks(ax, ticks, letter) : nothing
pyaxis[:set_tick_params](direction = axis[:tick_direction] == :out ? "out" : "in")
ax[Symbol("set_", letter, "label")](axis[:guide])
if get(axis.d, :flip, false)
if get(axis.plotattributes, :flip, false)
ax[Symbol("invert_", letter, "axis")]()
end
pyaxis[:label][:set_fontsize](py_thickness_scale(plt, axis[:guidefontsize]))
@@ -1226,6 +1221,7 @@ const _pyplot_legend_pos = KW(
function py_add_legend(plt::Plot, sp::Subplot, ax)
leg = sp[:legend]
clims = get_clims(sp)
if leg != :none
# gotta do this to ensure both axes are included
labels = []
@@ -1235,19 +1231,19 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
# add a line/marker and a label
push!(handles, if series[:seriestype] == :shape || series[:fillrange] != nothing
pypatches[:Patch](
edgecolor = py_color(get_linecolor(series), get_linealpha(series)),
facecolor = py_color(get_fillcolor(series), get_fillalpha(series)),
edgecolor = py_color(get_linecolor(series, clims), get_linealpha(series)),
facecolor = py_color(get_fillcolor(series, clims), get_fillalpha(series)),
linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)),
linestyle = py_linestyle(series[:seriestype], get_linestyle(series))
)
elseif series[:seriestype] in (:path, :straightline)
PyPlot.plt[:Line2D]((0,1),(0,0),
color = py_color(get_linecolor(series), get_linealpha(series)),
color = py_color(get_linecolor(series, clims), get_linealpha(series)),
linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)),
linestyle = py_linestyle(:path, get_linestyle(series)),
marker = py_marker(series[:markershape]),
markeredgecolor = py_color(get_markerstrokecolor(series), get_markerstrokealpha(series)),
markerfacecolor = series[:marker_z] == nothing ? py_color(get_markercolor(series), get_markeralpha(series)) : py_color(series[:markercolor][0.5])
markerfacecolor = series[:marker_z] == nothing ? py_color(get_markercolor(series, clims), get_markeralpha(series)) : py_color(series[:markercolor][0.5])
)
else
series[:serieshandle][1]
+1 -1
View File
@@ -49,7 +49,7 @@ end
# ----------------------------------------------------------------
# Override this to update plot items (title, xlabel, etc), and add annotations (d[:annotations])
# Override this to update plot items (title, xlabel, etc), and add annotations (plotattributes[:annotations])
function _update_plot_object(plt::Plot{[PkgName]Backend})
end
+10 -10
View File
@@ -25,7 +25,7 @@ const _unicodeplots_scale = [:identity]
# don't warn on unsupported... there's just too many warnings!!
warnOnUnsupported_args(::UnicodePlotsBackend, d::KW) = nothing
warnOnUnsupported_args(::UnicodePlotsBackend, plotattributes::KW) = nothing
# --------------------------------------------------------------------------------------
@@ -104,7 +104,7 @@ function rebuildUnicodePlot!(plt::Plot, width, height)
# now use the ! functions to add to the plot
for series in series_list(sp)
addUnicodeSeries!(o, series.d, sp[:legend] != :none, xlim, ylim)
addUnicodeSeries!(o, series.plotattributes, sp[:legend] != :none, xlim, ylim)
end
# save the object
@@ -114,17 +114,17 @@ end
# add a single series
function addUnicodeSeries!(o, d::KW, addlegend::Bool, xlim, ylim)
function addUnicodeSeries!(o, plotattributes::KW, addlegend::Bool, xlim, ylim)
# get the function, or special handling for step/bar/hist
st = d[:seriestype]
st = plotattributes[:seriestype]
if st == :histogram2d
UnicodePlots.densityplot!(o, d[:x], d[:y])
UnicodePlots.densityplot!(o, plotattributes[:x], plotattributes[:y])
return
end
if st in (:path, :straightline)
func = UnicodePlots.lineplot!
elseif st == :scatter || d[:markershape] != :none
elseif st == :scatter || plotattributes[:markershape] != :none
func = UnicodePlots.scatterplot!
# elseif st == :bar
# func = UnicodePlots.barplot!
@@ -136,16 +136,16 @@ function addUnicodeSeries!(o, d::KW, addlegend::Bool, xlim, ylim)
# get the series data and label
x, y = if st == :straightline
straightline_data(d)
straightline_data(plotattributes)
elseif st == :shape
shape_data(series)
else
[collect(float(d[s])) for s in (:x, :y)]
[collect(float(plotattributes[s])) for s in (:x, :y)]
end
label = addlegend ? d[:label] : ""
label = addlegend ? plotattributes[:label] : ""
# if we happen to pass in allowed color symbols, great... otherwise let UnicodePlots decide
color = d[:linecolor] in UnicodePlots.color_cycle ? d[:linecolor] : :auto
color = plotattributes[:linecolor] in UnicodePlots.color_cycle ? plotattributes[:linecolor] : :auto
# add the series
x, y = Plots.unzip(collect(Base.Iterators.filter(xy->isfinite(xy[1])&&isfinite(xy[2]), zip(x,y))))
+15 -15
View File
@@ -95,9 +95,9 @@ const _glyphtypes = KW(
)
function bokeh_glyph_type(d::KW)
st = d[:seriestype]
mt = d[:markershape]
function bokeh_glyph_type(plotattributes::KW)
st = plotattributes[:seriestype]
mt = plotattributes[:markershape]
if st == :scatter && mt == :none
mt = :circle
end
@@ -125,7 +125,7 @@ end
# ---------------------------------------------------------------------------
# function _create_plot(pkg::BokehBackend, d::KW)
# function _create_plot(pkg::BokehBackend, plotattributes::KW)
function _create_backend_figure(plt::Plot{BokehBackend})
# TODO: create the window/canvas/context that is the plot within the backend (call it `o`)
# TODO: initialize the plot... title, xlabel, bgcolor, etc
@@ -142,34 +142,34 @@ function _create_backend_figure(plt::Plot{BokehBackend})
extra_args = KW() # TODO: we'll put extra settings (xlim, etc) here
Bokeh.Plot(datacolumns, tools, filename, title, w, h, xaxis_type, yaxis_type, legend) #, extra_args)
# Plot(bplt, pkg, 0, d, KW[])
# Plot(bplt, pkg, 0, plotattributes, KW[])
end
# function _series_added(::BokehBackend, plt::Plot, d::KW)
# function _series_added(::BokehBackend, plt::Plot, plotattributes::KW)
function _series_added(plt::Plot{BokehBackend}, series::Series)
bdata = Dict{Symbol, Vector}(:x => collect(series.d[:x]), :y => collect(series.d[:y]))
bdata = Dict{Symbol, Vector}(:x => collect(series.plotattributes[:x]), :y => collect(series.plotattributes[:y]))
glyph = Bokeh.Bokehjs.Glyph(
glyphtype = bokeh_glyph_type(d),
linecolor = webcolor(d[:linecolor]), # shape's stroke or line color
linewidth = d[:linewidth], # shape's stroke width or line width
fillcolor = webcolor(d[:markercolor]),
size = ceil(Int, d[:markersize] * 2.5), # magic number 2.5 to keep in same scale as other backends
dash = get_stroke_vector(d[:linestyle])
glyphtype = bokeh_glyph_type(plotattributes),
linecolor = webcolor(plotattributes[:linecolor]), # shape's stroke or line color
linewidth = plotattributes[:linewidth], # shape's stroke width or line width
fillcolor = webcolor(plotattributes[:markercolor]),
size = ceil(Int, plotattributes[:markersize] * 2.5), # magic number 2.5 to keep in same scale as other backends
dash = get_stroke_vector(plotattributes[:linestyle])
)
legend = nothing # TODO
push!(plt.o.datacolumns, Bokeh.BokehDataSet(bdata, glyph, legend))
# push!(plt.seriesargs, d)
# push!(plt.seriesargs, plotattributes)
# plt
end
# ----------------------------------------------------------------
# TODO: override this to update plot items (title, xlabel, etc) after creation
function _update_plot_object(plt::Plot{BokehBackend}, d::KW)
function _update_plot_object(plt::Plot{BokehBackend}, plotattributes::KW)
end
# ----------------------------------------------------------------
+107 -107
View File
@@ -51,32 +51,32 @@ end
# Base.size(v::MissingVec) = (1,)
# Base.getindex(v::MissingVec, i::Integer) = 0.0
function createGadflyPlotObject(d::KW)
function createGadflyPlotObject(plotattributes::KW)
gplt = Gadfly.Plot()
gplt.mapping = Dict()
gplt.data_source = Gadfly.DataFrames.DataFrame()
# gplt.layers = gplt.layers[1:0]
gplt.layers = [Gadfly.layer(Gadfly.Geom.point(tag=:remove), x=zeros(1), y=zeros(1));] # x=MissingVec(), y=MissingVec());]
gplt.guides = Gadfly.GuideElement[Gadfly.Guide.xlabel(d[:xguide]),
Gadfly.Guide.ylabel(d[:yguide]),
Gadfly.Guide.title(d[:title])]
gplt.guides = Gadfly.GuideElement[Gadfly.Guide.xlabel(plotattributes[:xguide]),
Gadfly.Guide.ylabel(plotattributes[:yguide]),
Gadfly.Guide.title(plotattributes[:title])]
gplt
end
# ---------------------------------------------------------------------------
function getLineGeom(d::KW)
st = d[:seriestype]
xbins, ybins = maketuple(d[:bins])
function getLineGeom(plotattributes::KW)
st = plotattributes[:seriestype]
xbins, ybins = maketuple(plotattributes[:bins])
if st == :hexb
Gadfly.Geom.hexbin(xbincount = xbins, ybincount = ybins)
elseif st == :histogram2d
Gadfly.Geom.histogram2d(xbincount = xbins, ybincount = ybins)
elseif st == :histogram
Gadfly.Geom.histogram(bincount = xbins,
orientation = isvertical(d) ? :vertical : :horizontal,
position = d[:bar_position] == :stack ? :stack : :dodge)
orientation = isvertical(plotattributes) ? :vertical : :horizontal,
position = plotattributes[:bar_position] == :stack ? :stack : :dodge)
elseif st == :path
Gadfly.Geom.path
elseif st in (:bar, :sticks)
@@ -90,7 +90,7 @@ function getLineGeom(d::KW)
elseif st == :vline
Gadfly.Geom.vline
elseif st == :contour
Gadfly.Geom.contour(levels = d[:levels])
Gadfly.Geom.contour(levels = plotattributes[:levels])
# elseif st == :shape
# Gadfly.Geom.polygon(fill = true, preserve_order = true)
else
@@ -98,11 +98,11 @@ function getLineGeom(d::KW)
end
end
function get_extra_theme_args(d::KW, k::Symbol)
function get_extra_theme_args(plotattributes::KW, k::Symbol)
# gracefully handles old Gadfly versions
extra_theme_args = KW()
try
extra_theme_args[:line_style] = Gadfly.get_stroke_vector(d[k])
extra_theme_args[:line_style] = Gadfly.get_stroke_vector(plotattributes[k])
catch err
if string(err) == "UndefVarError(:get_stroke_vector)"
Base.warn_once("Gadfly.get_stroke_vector failed... do you have an old version of Gadfly?")
@@ -113,53 +113,53 @@ function get_extra_theme_args(d::KW, k::Symbol)
extra_theme_args
end
function getGadflyLineTheme(d::KW)
st = d[:seriestype]
lc = convertColor(getColor(d[:linecolor]), d[:linealpha])
fc = convertColor(getColor(d[:fillcolor]), d[:fillalpha])
function getGadflyLineTheme(plotattributes::KW)
st = plotattributes[:seriestype]
lc = convertColor(getColor(plotattributes[:linecolor]), plotattributes[:linealpha])
fc = convertColor(getColor(plotattributes[:fillcolor]), plotattributes[:fillalpha])
Gadfly.Theme(;
default_color = (st in (:histogram,:histogram2d,:hexbin,:bar,:sticks) ? fc : lc),
line_width = (st == :sticks ? 1 : d[:linewidth]) * Gadfly.px,
# line_style = Gadfly.get_stroke_vector(d[:linestyle]),
line_width = (st == :sticks ? 1 : plotattributes[:linewidth]) * Gadfly.px,
# line_style = Gadfly.get_stroke_vector(plotattributes[:linestyle]),
lowlight_color = x->RGB(fc), # fill/ribbon
lowlight_opacity = alpha(fc), # fill/ribbon
bar_highlight = RGB(lc), # bars
get_extra_theme_args(d, :linestyle)...
get_extra_theme_args(plotattributes, :linestyle)...
)
end
# add a line as a new layer
function addGadflyLine!(plt::Plot, numlayers::Int, d::KW, geoms...)
function addGadflyLine!(plt::Plot, numlayers::Int, plotattributes::KW, geoms...)
gplt = getGadflyContext(plt)
gfargs = vcat(geoms..., getGadflyLineTheme(d))
gfargs = vcat(geoms..., getGadflyLineTheme(plotattributes))
kwargs = KW()
st = d[:seriestype]
st = plotattributes[:seriestype]
# add a fill?
if d[:fillrange] != nothing && st != :contour
fillmin, fillmax = map(makevec, maketuple(d[:fillrange]))
if plotattributes[:fillrange] != nothing && st != :contour
fillmin, fillmax = map(makevec, maketuple(plotattributes[:fillrange]))
nmin, nmax = length(fillmin), length(fillmax)
kwargs[:ymin] = Float64[min(y, fillmin[mod1(i, nmin)], fillmax[mod1(i, nmax)]) for (i,y) in enumerate(d[:y])]
kwargs[:ymax] = Float64[max(y, fillmin[mod1(i, nmin)], fillmax[mod1(i, nmax)]) for (i,y) in enumerate(d[:y])]
kwargs[:ymin] = Float64[min(y, fillmin[mod1(i, nmin)], fillmax[mod1(i, nmax)]) for (i,y) in enumerate(plotattributes[:y])]
kwargs[:ymax] = Float64[max(y, fillmin[mod1(i, nmin)], fillmax[mod1(i, nmax)]) for (i,y) in enumerate(plotattributes[:y])]
push!(gfargs, Gadfly.Geom.ribbon)
end
if st in (:hline, :vline)
kwargs[st == :hline ? :yintercept : :xintercept] = d[:y]
kwargs[st == :hline ? :yintercept : :xintercept] = plotattributes[:y]
else
if st == :sticks
w = 0.01 * mean(diff(d[:x]))
kwargs[:xmin] = d[:x] - w
kwargs[:xmax] = d[:x] + w
w = 0.01 * mean(diff(plotattributes[:x]))
kwargs[:xmin] = plotattributes[:x] - w
kwargs[:xmax] = plotattributes[:x] + w
elseif st == :contour
kwargs[:z] = d[:z].surf
addGadflyContColorScale(plt, d[:linecolor])
kwargs[:z] = plotattributes[:z].surf
addGadflyContColorScale(plt, plotattributes[:linecolor])
end
kwargs[:x] = d[st == :histogram ? :y : :x]
kwargs[:y] = d[:y]
kwargs[:x] = plotattributes[st == :histogram ? :y : :x]
kwargs[:y] = plotattributes[:y]
end
@@ -180,22 +180,22 @@ getMarkerGeom(other) = gadflyshape(get_shape(other))
# getMarkerGeom(shape::Shape) = gadflyshape(shape)
# getMarkerGeom(shape::Symbol) = gadflyshape(_shapes[shape])
# getMarkerGeom(shapes::AVec) = gadflyshape(map(gadflyshape, shapes)) # map(getMarkerGeom, shapes)
function getMarkerGeom(d::KW)
if d[:seriestype] == :shape
function getMarkerGeom(plotattributes::KW)
if plotattributes[:seriestype] == :shape
Gadfly.Geom.polygon(fill = true, preserve_order = true)
else
getMarkerGeom(d[:markershape])
getMarkerGeom(plotattributes[:markershape])
end
end
function getGadflyMarkerTheme(d::KW, attr::KW)
c = getColor(d[:markercolor])
α = d[:markeralpha]
function getGadflyMarkerTheme(plotattributes::KW, attr::KW)
c = getColor(plotattributes[:markercolor])
α = plotattributes[:markeralpha]
if α != nothing
c = RGBA(RGB(c), α)
end
ms = d[:markersize]
ms = plotattributes[:markersize]
ms = if typeof(ms) <: AVec
@warn("Gadfly doesn't support variable marker sizes... using the average: $(mean(ms))")
mean(ms) * Gadfly.px
@@ -206,10 +206,10 @@ function getGadflyMarkerTheme(d::KW, attr::KW)
Gadfly.Theme(;
default_color = c,
default_point_size = ms,
discrete_highlight_color = c -> RGB(getColor(d[:markerstrokecolor])),
highlight_width = d[:markerstrokewidth] * Gadfly.px,
line_width = d[:markerstrokewidth] * Gadfly.px,
# get_extra_theme_args(d, :markerstrokestyle)...
discrete_highlight_color = c -> RGB(getColor(plotattributes[:markerstrokecolor])),
highlight_width = plotattributes[:markerstrokewidth] * Gadfly.px,
line_width = plotattributes[:markerstrokewidth] * Gadfly.px,
# get_extra_theme_args(plotattributes, :markerstrokestyle)...
)
end
@@ -221,25 +221,25 @@ function addGadflyContColorScale(plt::Plot{GadflyBackend}, c)
push!(getGadflyContext(plt).scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(c, p))))
end
function addGadflyMarker!(plt::Plot, numlayers::Int, d::KW, attr::KW, geoms...)
gfargs = vcat(geoms..., getGadflyMarkerTheme(d, attr), getMarkerGeom(d))
function addGadflyMarker!(plt::Plot, numlayers::Int, plotattributes::KW, attr::KW, geoms...)
gfargs = vcat(geoms..., getGadflyMarkerTheme(plotattributes, attr), getMarkerGeom(plotattributes))
kwargs = KW()
# handle continuous color scales for the markers
zcolor = d[:marker_z]
zcolor = plotattributes[:marker_z]
if zcolor != nothing && typeof(zcolor) <: AVec
kwargs[:color] = zcolor
addGadflyContColorScale(plt, d[:markercolor])
addGadflyContColorScale(plt, plotattributes[:markercolor])
end
Gadfly.layer(gfargs...; x = d[:x], y = d[:y], order=numlayers, kwargs...)
Gadfly.layer(gfargs...; x = plotattributes[:x], y = plotattributes[:y], order=numlayers, kwargs...)
end
# ---------------------------------------------------------------------------
function addToGadflyLegend(plt::Plot, d::KW)
if plt.attr[:legend] != :none && d[:label] != ""
function addToGadflyLegend(plt::Plot, plotattributes::KW)
if plt.attr[:legend] != :none && plotattributes[:label] != ""
gplt = getGadflyContext(plt)
# add the legend if needed
@@ -254,20 +254,20 @@ function addToGadflyLegend(plt::Plot, d::KW)
# since gadfly will call unique(colors), but doesn't also merge the rows that match
# Should ensure from this side that colors which are the same are merged together
c = getColor(d[d[:markershape] == :none ? :linecolor : :markercolor])
c = getColor(plotattributes[plotattributes[:markershape] == :none ? :linecolor : :markercolor])
foundit = false
# extend the label if we found this color
for i in 1:length(guide.colors)
if RGB(c) == guide.colors[i]
guide.labels[i] *= ", " * d[:label]
guide.labels[i] *= ", " * plotattributes[:label]
foundit = true
end
end
# didn't find the color, so add a new entry into the legend
if !foundit
push!(guide.labels, d[:label])
push!(guide.labels, plotattributes[:label])
push!(guide.colors, c)
end
end
@@ -279,40 +279,40 @@ getGadflySmoothing(smooth::Bool) = smooth ? [Gadfly.Geom.smooth(method=:lm)] : A
getGadflySmoothing(smooth::Real) = [Gadfly.Geom.smooth(method=:loess, smoothing=float(smooth))]
function addGadflySeries!(plt::Plot, d::KW)
function addGadflySeries!(plt::Plot, plotattributes::KW)
layers = Gadfly.Layer[]
gplt = getGadflyContext(plt)
# add a regression line?
# TODO: make more flexible
smooth = getGadflySmoothing(d[:smooth])
smooth = getGadflySmoothing(plotattributes[:smooth])
# lines
geom = getLineGeom(d)
geom = getLineGeom(plotattributes)
if geom != nothing
prepend!(layers, addGadflyLine!(plt, length(gplt.layers), d, geom, smooth...))
prepend!(layers, addGadflyLine!(plt, length(gplt.layers), plotattributes, geom, smooth...))
smooth = Any[] # don't add a regression for markers too
end
# special handling for ohlc and scatter
st = d[:seriestype]
st = plotattributes[:seriestype]
# if st == :ohlc
# error("Haven't re-implemented after refactoring")
if st in (:histogram2d, :hexbin) && (isa(d[:fillcolor], ColorGradient) || isa(d[:fillcolor], ColorFunction))
push!(gplt.scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(d[:fillcolor], p))))
elseif st == :scatter && d[:markershape] == :none
d[:markershape] = :circle
if st in (:histogram2d, :hexbin) && (isa(plotattributes[:fillcolor], ColorGradient) || isa(plotattributes[:fillcolor], ColorFunction))
push!(gplt.scales, Gadfly.Scale.ContinuousColorScale(p -> RGB(getColorZ(plotattributes[:fillcolor], p))))
elseif st == :scatter && plotattributes[:markershape] == :none
plotattributes[:markershape] = :circle
end
# markers
if d[:markershape] != :none || st == :shape
prepend!(layers, addGadflyMarker!(plt, length(gplt.layers), d, plt.attr, smooth...))
if plotattributes[:markershape] != :none || st == :shape
prepend!(layers, addGadflyMarker!(plt, length(gplt.layers), plotattributes, plt.attr, smooth...))
end
st in (:histogram2d, :hexbin, :contour) || addToGadflyLegend(plt, d)
st in (:histogram2d, :hexbin, :contour) || addToGadflyLegend(plt, plotattributes)
# now save the layers that apply to this series
d[:gadflylayers] = layers
plotattributes[:gadflylayers] = layers
prepend!(gplt.layers, layers)
end
@@ -322,10 +322,10 @@ end
# NOTE: I'm leaving this here and commented out just in case I want to implement again... it was hacky code to create multi-colored line segments
# # colorgroup
# z = d[:z]
# z = plotattributes[:z]
# # handle line segments of different colors
# cscheme = d[:linecolor]
# cscheme = plotattributes[:linecolor]
# if isa(cscheme, ColorVector)
# # create a color scale, and set the color group to the index of the color
# push!(gplt.scales, Gadfly.Scale.color_discrete_manual(cscheme.v...))
@@ -333,10 +333,10 @@ end
# # this is super weird, but... oh well... for some reason this creates n separate line segments...
# # create a list of vertices that go: [x1,x2,x2,x3,x3, ... ,xi,xi, ... xn,xn] (same for y)
# # then the vector passed to the "color" keyword should be a vector: [1,1,2,2,3,3,4,4, ..., i,i, ... , n,n]
# csindices = Int[mod1(i,length(cscheme.v)) for i in 1:length(d[:y])]
# csindices = Int[mod1(i,length(cscheme.v)) for i in 1:length(plotattributes[:y])]
# cs = collect(repeat(csindices', 2, 1))[1:end-1]
# grp = collect(repeat((1:length(d[:y]))', 2, 1))[1:end-1]
# d[:x], d[:y] = map(createSegments, (d[:x], d[:y]))
# grp = collect(repeat((1:length(plotattributes[:y]))', 2, 1))[1:end-1]
# plotattributes[:x], plotattributes[:y] = map(createSegments, (plotattributes[:x], plotattributes[:y]))
# colorgroup = [(:linecolor, cs), (:group, grp)]
@@ -388,11 +388,11 @@ continuousAndSameAxis(scale, isx::Bool) = isa(scale, Gadfly.Scale.ContinuousScal
filterGadflyScale(gplt, isx::Bool) = filter!(scale -> !continuousAndSameAxis(scale, isx), gplt.scales)
function getGadflyScaleFunction(d::KW, isx::Bool)
function getGadflyScaleFunction(plotattributes::KW, isx::Bool)
scalekey = isx ? :xscale : :yscale
hasScaleKey = haskey(d, scalekey)
hasScaleKey = haskey(plotattributes, scalekey)
if hasScaleKey
scale = d[scalekey]
scale = plotattributes[scalekey]
scale == :ln && return isx ? Gadfly.Scale.x_log : Gadfly.Scale.y_log, hasScaleKey, log
scale == :log2 && return isx ? Gadfly.Scale.x_log2 : Gadfly.Scale.y_log2, hasScaleKey, log2
scale == :log10 && return isx ? Gadfly.Scale.x_log10 : Gadfly.Scale.y_log10, hasScaleKey, log10
@@ -403,15 +403,15 @@ function getGadflyScaleFunction(d::KW, isx::Bool)
end
function addGadflyLimitsScale(gplt, d::KW, isx::Bool)
gfunc, hasScaleKey, func = getGadflyScaleFunction(d, isx)
function addGadflyLimitsScale(gplt, plotattributes::KW, isx::Bool)
gfunc, hasScaleKey, func = getGadflyScaleFunction(plotattributes, isx)
# do we want to add min/max limits for the axis?
limsym = isx ? :xlims : :ylims
limargs = Any[]
# map :auto to nothing, otherwise add to limargs
lims = get(d, limsym, :auto)
lims = get(plotattributes, limsym, :auto)
if lims == :auto
lims = nothing
else
@@ -432,7 +432,7 @@ function addGadflyLimitsScale(gplt, d::KW, isx::Bool)
lims, func
end
function updateGadflyAxisFlips(gplt, d::KW, xlims, ylims, xfunc, yfunc)
function updateGadflyAxisFlips(gplt, plotattributes::KW, xlims, ylims, xfunc, yfunc)
if isa(gplt.coord, Gadfly.Coord.Cartesian)
gplt.coord = Gadfly.Coord.cartesian(
gplt.coord.xvars,
@@ -441,16 +441,16 @@ function updateGadflyAxisFlips(gplt, d::KW, xlims, ylims, xfunc, yfunc)
xmax = xlims == nothing ? gplt.coord.xmax : xfunc(maximum(xlims)),
ymin = ylims == nothing ? gplt.coord.ymin : yfunc(minimum(ylims)),
ymax = ylims == nothing ? gplt.coord.ymax : yfunc(maximum(ylims)),
xflip = get(d, :xflip, gplt.coord.xflip),
yflip = get(d, :yflip, gplt.coord.yflip),
xflip = get(plotattributes, :xflip, gplt.coord.xflip),
yflip = get(plotattributes, :yflip, gplt.coord.yflip),
fixed = gplt.coord.fixed,
aspect_ratio = gplt.coord.aspect_ratio,
raster = gplt.coord.raster
)
else
gplt.coord = Gadfly.Coord.Cartesian(
xflip = get(d, :xflip, false),
yflip = get(d, :yflip, false)
xflip = get(plotattributes, :xflip, false),
yflip = get(plotattributes, :yflip, false)
)
end
end
@@ -464,37 +464,37 @@ function findGuideAndSet(gplt, t::DataType, args...; kw...)
end
end
function updateGadflyGuides(plt::Plot, d::KW)
function updateGadflyGuides(plt::Plot, plotattributes::KW)
gplt = getGadflyContext(plt)
haskey(d, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, string(d[:title]))
haskey(d, :xguide) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, string(d[:xguide]))
haskey(d, :yguide) && findGuideAndSet(gplt, Gadfly.Guide.ylabel, string(d[:yguide]))
haskey(plotattributes, :title) && findGuideAndSet(gplt, Gadfly.Guide.title, string(plotattributes[:title]))
haskey(plotattributes, :xguide) && findGuideAndSet(gplt, Gadfly.Guide.xlabel, string(plotattributes[:xguide]))
haskey(plotattributes, :yguide) && findGuideAndSet(gplt, Gadfly.Guide.ylabel, string(plotattributes[:yguide]))
xlims, xfunc = addGadflyLimitsScale(gplt, d, true)
ylims, yfunc = addGadflyLimitsScale(gplt, d, false)
xlims, xfunc = addGadflyLimitsScale(gplt, plotattributes, true)
ylims, yfunc = addGadflyLimitsScale(gplt, plotattributes, false)
ticks = get(d, :xticks, :auto)
ticks = get(plotattributes, :xticks, :auto)
if ticks == :none
_remove_axis(plt, true)
else
addGadflyTicksGuide(gplt, ticks, true)
end
ticks = get(d, :yticks, :auto)
ticks = get(plotattributes, :yticks, :auto)
if ticks == :none
_remove_axis(plt, false)
else
addGadflyTicksGuide(gplt, ticks, false)
end
updateGadflyAxisFlips(gplt, d, xlims, ylims, xfunc, yfunc)
updateGadflyAxisFlips(gplt, plotattributes, xlims, ylims, xfunc, yfunc)
end
function updateGadflyPlotTheme(plt::Plot, d::KW)
function updateGadflyPlotTheme(plt::Plot, plotattributes::KW)
kwargs = KW()
# colors
insidecolor, gridcolor, textcolor, guidecolor, legendcolor =
map(s -> getColor(d[s]), (
map(s -> getColor(plotattributes[s]), (
:background_color_inside,
:foreground_color_grid,
:foreground_color_text,
@@ -503,17 +503,17 @@ function updateGadflyPlotTheme(plt::Plot, d::KW)
))
# # hide the legend?
leg = d[d[:legend] == :none ? :colorbar : :legend]
leg = plotattributes[plotattributes[:legend] == :none ? :colorbar : :legend]
if leg != :best
kwargs[:key_position] = leg == :inside ? :right : leg
end
if !get(d, :grid, true)
if !get(plotattributes, :grid, true)
kwargs[:grid_color] = gridcolor
end
# fonts
tfont, gfont, lfont = d[:tickfont], d[:guidefont], d[:legendfont]
tfont, gfont, lfont = plotattributes[:tickfont], plotattributes[:guidefont], plotattributes[:legendfont]
getGadflyContext(plt).theme = Gadfly.Theme(;
background_color = insidecolor,
@@ -568,9 +568,9 @@ end
# ---------------------------------------------------------------------------
# create a blank Gadfly.Plot object
# function _create_plot(pkg::GadflyBackend, d::KW)
# gplt = createGadflyPlotObject(d)
# Plot(gplt, pkg, 0, d, KW[])
# function _create_plot(pkg::GadflyBackend, plotattributes::KW)
# gplt = createGadflyPlotObject(plotattributes)
# Plot(gplt, pkg, 0, plotattributes, KW[])
# end
function _create_backend_figure(plt::Plot{GadflyBackend})
createGadflyPlotObject(plt.attr)
@@ -578,7 +578,7 @@ end
# plot one data series
# function _series_added(::GadflyBackend, plt::Plot, d::KW)
# function _series_added(::GadflyBackend, plt::Plot, plotattributes::KW)
function _series_added(plt::Plot{GadflyBackend}, series::Series)
# first clear out the temporary layer
gplt = getGadflyContext(plt)
@@ -586,16 +586,16 @@ function _series_added(plt::Plot{GadflyBackend}, series::Series)
gplt.layers = gplt.layers[2:end]
end
addGadflySeries!(plt, series.d)
# push!(plt.seriesargs, d)
addGadflySeries!(plt, series.plotattributes)
# push!(plt.seriesargs, plotattributes)
# plt
end
function _update_plot_object(plt::Plot{GadflyBackend}, d::KW)
updateGadflyGuides(plt, d)
updateGadflyPlotTheme(plt, d)
function _update_plot_object(plt::Plot{GadflyBackend}, plotattributes::KW)
updateGadflyGuides(plt, plotattributes)
updateGadflyPlotTheme(plt, plotattributes)
end
+16 -16
View File
@@ -18,9 +18,9 @@ function _initialize_backend(::ImmerseBackend; kw...)
end
end
function createImmerseFigure(d::KW)
w,h = d[:size]
figidx = Immerse.figure(; name = d[:window_title], width = w, height = h)
function createImmerseFigure(plotattributes::KW)
w,h = plotattributes[:size]
figidx = Immerse.figure(; name = plotattributes[:window_title], width = w, height = h)
Immerse.Figure(figidx)
end
@@ -28,12 +28,12 @@ end
# create a blank Gadfly.Plot object
# function _create_plot(pkg::ImmerseBackend, d::KW)
# function _create_plot(pkg::ImmerseBackend, plotattributes::KW)
# # create the underlying Gadfly.Plot object
# gplt = createGadflyPlotObject(d)
# gplt = createGadflyPlotObject(plotattributes)
#
# # save both the Immerse.Figure and the Gadfly.Plot
# Plot((nothing,gplt), pkg, 0, d, KW[])
# Plot((nothing,gplt), pkg, 0, plotattributes, KW[])
# end
function _create_backend_figure(plt::Plot{ImmerseBackend})
(nothing, createGadflyPlotObject(plt.attr))
@@ -41,20 +41,20 @@ end
# # plot one data series
# function _series_added(::ImmerseBackend, plt::Plot, d::KW)
# addGadflySeries!(plt, d)
# push!(plt.seriesargs, d)
# function _series_added(::ImmerseBackend, plt::Plot, plotattributes::KW)
# addGadflySeries!(plt, plotattributes)
# push!(plt.seriesargs, plotattributes)
# plt
# end
function _series_added(plt::Plot{ImmerseBackend}, series::Series)
addGadflySeries!(plt, series.d)
addGadflySeries!(plt, series.plotattributes)
end
function _update_plot_object(plt::Plot{ImmerseBackend}, d::KW)
updateGadflyGuides(plt, d)
updateGadflyPlotTheme(plt, d)
function _update_plot_object(plt::Plot{ImmerseBackend}, plotattributes::KW)
updateGadflyGuides(plt, plotattributes)
updateGadflyPlotTheme(plt, plotattributes)
end
@@ -94,10 +94,10 @@ end
#
# function showSubplotObject(subplt::Subplot{ImmerseBackend})
# # create the Gtk window with vertical box vsep
# d = getattr(subplt,1)
# w,h = d[:size]
# plotattributes = getattr(subplt,1)
# w,h = plotattributes[:size]
# vsep = Gtk.GtkBoxLeaf(:v)
# win = Gtk.GtkWindowLeaf(vsep, d[:window_title], w, h)
# win = Gtk.GtkWindowLeaf(vsep, plotattributes[:window_title], w, h)
#
# figindices = []
# row = Gtk.GtkBoxLeaf(:h)
+53 -53
View File
@@ -52,84 +52,84 @@ const _qwtAliases = KW(
:star8 => :star2,
)
function fixcolors(d::KW)
for (k,v) in d
function fixcolors(plotattributes::KW)
for (k,v) in plotattributes
if typeof(v) <: ColorScheme
d[k] = getColor(v)
plotattributes[k] = getColor(v)
end
end
end
function replaceQwtAliases(d, s)
if haskey(_qwtAliases, d[s])
d[s] = _qwtAliases[d[s]]
function replaceQwtAliases(plotattributes, s)
if haskey(_qwtAliases, plotattributes[s])
plotattributes[s] = _qwtAliases[plotattributes[s]]
end
end
function adjustQwtKeywords(plt::Plot{QwtBackend}, iscreating::Bool; kw...)
d = KW(kw)
st = d[:seriestype]
plotattributes = KW(kw)
st = plotattributes[:seriestype]
if st == :scatter
d[:seriestype] = :none
if d[:markershape] == :none
d[:markershape] = :circle
plotattributes[:seriestype] = :none
if plotattributes[:markershape] == :none
plotattributes[:markershape] = :circle
end
elseif st in (:hline, :vline)
addLineMarker(plt, d)
d[:seriestype] = :none
d[:markershape] = :circle
d[:markersize] = 1
addLineMarker(plt, plotattributes)
plotattributes[:seriestype] = :none
plotattributes[:markershape] = :circle
plotattributes[:markersize] = 1
if st == :vline
d[:x], d[:y] = d[:y], d[:x]
plotattributes[:x], plotattributes[:y] = plotattributes[:y], plotattributes[:x]
end
elseif !iscreating && st == :bar
d = barHack(; kw...)
plotattributes = barHack(; kw...)
elseif !iscreating && st == :histogram
d = barHack(; histogramHack(; kw...)...)
plotattributes = barHack(; histogramHack(; kw...)...)
end
replaceQwtAliases(d, :seriestype)
replaceQwtAliases(d, :markershape)
replaceQwtAliases(plotattributes, :seriestype)
replaceQwtAliases(plotattributes, :markershape)
for k in keys(d)
for k in keys(plotattributes)
if haskey(_qwtAliases, k)
d[_qwtAliases[k]] = d[k]
plotattributes[_qwtAliases[k]] = plotattributes[k]
end
end
d[:x] = collect(d[:x])
d[:y] = collect(d[:y])
plotattributes[:x] = collect(plotattributes[:x])
plotattributes[:y] = collect(plotattributes[:y])
d
plotattributes
end
# function _create_plot(pkg::QwtBackend, d::KW)
# function _create_plot(pkg::QwtBackend, plotattributes::KW)
function _create_backend_figure(plt::Plot{QwtBackend})
fixcolors(plt.attr)
dumpdict(plt.attr,"\n\n!!! plot")
o = Qwt.plot(zeros(0,0); plt.attr..., show=false)
# plt = Plot(o, pkg, 0, d, KW[])
# plt = Plot(o, pkg, 0, plotattributes, KW[])
# plt
end
# function _series_added(::QwtBackend, plt::Plot, d::KW)
# function _series_added(::QwtBackend, plt::Plot, plotattributes::KW)
function _series_added(plt::Plot{QwtBackend}, series::Series)
d = adjustQwtKeywords(plt, false; series.d...)
fixcolors(d)
dumpdict(d,"\n\n!!! plot!")
Qwt.oplot(plt.o; d...)
# push!(plt.seriesargs, d)
plotattributes = adjustQwtKeywords(plt, false; series.plotattributes...)
fixcolors(plotattributes)
dumpdict(plotattributes,"\n\n!!! plot!")
Qwt.oplot(plt.o; plotattributes...)
# push!(plt.seriesargs, plotattributes)
# plt
end
# ----------------------------------------------------------------
function updateLimsAndTicks(plt::Plot{QwtBackend}, d::KW, isx::Bool)
lims = get(d, isx ? :xlims : :ylims, nothing)
ticks = get(d, isx ? :xticks : :yticks, nothing)
function updateLimsAndTicks(plt::Plot{QwtBackend}, plotattributes::KW, isx::Bool)
lims = get(plotattributes, isx ? :xlims : :ylims, nothing)
ticks = get(plotattributes, isx ? :xticks : :yticks, nothing)
w = plt.o.widget
axisid = Qwt.QWT.QwtPlot[isx ? :xBottom : :yLeft]
@@ -155,8 +155,8 @@ function updateLimsAndTicks(plt::Plot{QwtBackend}, d::KW, isx::Bool)
# change the scale
scalesym = isx ? :xscale : :yscale
if haskey(d, scalesym)
scaletype = d[scalesym]
if haskey(plotattributes, scalesym)
scaletype = plotattributes[scalesym]
scaletype == :identity && w[:setAxisScaleEngine](axisid, Qwt.QWT.QwtLinearScaleEngine())
# scaletype == :log && w[:setAxisScaleEngine](axisid, Qwt.QWT.QwtLogScaleEngine(e))
# scaletype == :log2 && w[:setAxisScaleEngine](axisid, Qwt.QWT.QwtLogScaleEngine(2))
@@ -167,32 +167,32 @@ function updateLimsAndTicks(plt::Plot{QwtBackend}, d::KW, isx::Bool)
end
function _update_plot_object(plt::Plot{QwtBackend}, d::KW)
haskey(d, :title) && Qwt.title(plt.o, d[:title])
haskey(d, :xguide) && Qwt.xlabel(plt.o, d[:xguide])
haskey(d, :yguide) && Qwt.ylabel(plt.o, d[:yguide])
updateLimsAndTicks(plt, d, true)
updateLimsAndTicks(plt, d, false)
function _update_plot_object(plt::Plot{QwtBackend}, plotattributes::KW)
haskey(plotattributes, :title) && Qwt.title(plt.o, plotattributes[:title])
haskey(plotattributes, :xguide) && Qwt.xlabel(plt.o, plotattributes[:xguide])
haskey(plotattributes, :yguide) && Qwt.ylabel(plt.o, plotattributes[:yguide])
updateLimsAndTicks(plt, plotattributes, true)
updateLimsAndTicks(plt, plotattributes, false)
end
function _update_plot_pos_size(plt::AbstractPlot{QwtBackend}, d::KW)
haskey(d, :size) && Qwt.resizewidget(plt.o, d[:size]...)
haskey(d, :pos) && Qwt.movewidget(plt.o, d[:pos]...)
function _update_plot_pos_size(plt::AbstractPlot{QwtBackend}, plotattributes::KW)
haskey(plotattributes, :size) && Qwt.resizewidget(plt.o, plotattributes[:size]...)
haskey(plotattributes, :pos) && Qwt.movewidget(plt.o, plotattributes[:pos]...)
end
# ----------------------------------------------------------------
# curve.setPen(Qt.QPen(Qt.QColor(color), linewidth, self.getLineStyle(linestyle)))
function addLineMarker(plt::Plot{QwtBackend}, d::KW)
for yi in d[:y]
function addLineMarker(plt::Plot{QwtBackend}, plotattributes::KW)
for yi in plotattributes[:y]
marker = Qwt.QWT.QwtPlotMarker()
ishorizontal = (d[:seriestype] == :hline)
ishorizontal = (plotattributes[:seriestype] == :hline)
marker[:setLineStyle](ishorizontal ? 1 : 2)
marker[ishorizontal ? :setYValue : :setXValue](yi)
qcolor = Qwt.convertRGBToQColor(getColor(d[:linecolor]))
linestyle = plt.o.widget[:getLineStyle](string(d[:linestyle]))
marker[:setLinePen](Qwt.QT.QPen(qcolor, d[:linewidth], linestyle))
qcolor = Qwt.convertRGBToQColor(getColor(plotattributes[:linecolor]))
linestyle = plt.o.widget[:getLineStyle](string(plotattributes[:linestyle]))
marker[:setLinePen](Qwt.QT.QPen(qcolor, plotattributes[:linewidth], linestyle))
marker[:attach](plt.o.widget)
end
+40 -40
View File
@@ -75,10 +75,10 @@ function _create_backend_figure(plt::Plot{WinstonBackend})
)
end
copy_remove(d::KW, s::Symbol) = delete!(copy(d), s)
copy_remove(plotattributes::KW, s::Symbol) = delete!(copy(plotattributes), s)
function addRegressionLineWinston(d::KW, wplt)
xs, ys = regressionXY(d[:x], d[:y])
function addRegressionLineWinston(plotattributes::KW, wplt)
xs, ys = regressionXY(plotattributes[:x], plotattributes[:y])
Winston.add(wplt, Winston.Curve(xs, ys, kind="dotted"))
end
@@ -93,22 +93,22 @@ function getWinstonItems(plt::Plot)
end
function _series_added(plt::Plot{WinstonBackend}, series::Series)
d = series.d
plotattributes = series.plotattributes
window, canvas, wplt = getWinstonItems(plt)
# until we call it normally, do the hack
if d[:seriestype] == :bar
d = barHack(;d...)
if plotattributes[:seriestype] == :bar
plotattributes = barHack(;plotattributes...)
end
e = KW()
e[:color] = getColor(d[:linecolor])
e[:linewidth] = d[:linewidth]
e[:kind] = winston_linestyle[d[:linestyle]]
e[:symbolkind] = winston_marker[d[:markershape]]
e[:color] = getColor(plotattributes[:linecolor])
e[:linewidth] = plotattributes[:linewidth]
e[:kind] = winston_linestyle[plotattributes[:linestyle]]
e[:symbolkind] = winston_marker[plotattributes[:markershape]]
# markercolor # same choices as `color`, or :match will set the color to be the same as `color`
e[:symbolsize] = d[:markersize] / 5
e[:symbolsize] = plotattributes[:markersize] / 5
# pos # (Int,Int), move the enclosing window to this position
# screen # Integer, move enclosing window to this screen number (for multiscreen desktops)
@@ -116,69 +116,69 @@ function _series_added(plt::Plot{WinstonBackend}, series::Series)
## lintype :path, :step, :stepinverted, :sticks, :dots, :none, :histogram2d, :hexbin, :histogram, :bar
if d[:seriestype] == :none
Winston.add(wplt, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)..., color=getColor(d[:markercolor])))
if plotattributes[:seriestype] == :none
Winston.add(wplt, Winston.Points(plotattributes[:x], plotattributes[:y]; copy_remove(e, :kind)..., color=getColor(plotattributes[:markercolor])))
elseif d[:seriestype] == :path
x, y = d[:x], d[:y]
elseif plotattributes[:seriestype] == :path
x, y = plotattributes[:x], plotattributes[:y]
Winston.add(wplt, Winston.Curve(x, y; e...))
fillrange = d[:fillrange]
fillrange = plotattributes[:fillrange]
if fillrange != nothing
if isa(fillrange, AbstractVector)
y2 = fillrange
else
y2 = Float64[fillrange for yi in y]
end
Winston.add(wplt, Winston.FillBetween(x, y, x, y2, fillcolor=getColor(d[:fillcolor])))
Winston.add(wplt, Winston.FillBetween(x, y, x, y2, fillcolor=getColor(plotattributes[:fillcolor])))
end
elseif d[:seriestype] == :scatter
if d[:markershape] == :none
d[:markershape] = :circle
elseif plotattributes[:seriestype] == :scatter
if plotattributes[:markershape] == :none
plotattributes[:markershape] = :circle
end
# elseif d[:seriestype] == :step
# elseif plotattributes[:seriestype] == :step
# fn = Winston.XXX
# elseif d[:seriestype] == :stepinverted
# elseif plotattributes[:seriestype] == :stepinverted
# fn = Winston.XXX
elseif d[:seriestype] == :sticks
Winston.add(wplt, Winston.Stems(d[:x], d[:y]; e...))
elseif plotattributes[:seriestype] == :sticks
Winston.add(wplt, Winston.Stems(plotattributes[:x], plotattributes[:y]; e...))
# elseif d[:seriestype] == :dots
# elseif plotattributes[:seriestype] == :dots
# fn = Winston.XXX
# elseif d[:seriestype] == :histogram2d
# elseif plotattributes[:seriestype] == :histogram2d
# fn = Winston.XXX
# elseif d[:seriestype] == :hexbin
# elseif plotattributes[:seriestype] == :hexbin
# fn = Winston.XXX
elseif d[:seriestype] == :histogram
hst = hist(d[:y], d[:bins])
elseif plotattributes[:seriestype] == :histogram
hst = hist(plotattributes[:y], plotattributes[:bins])
Winston.add(wplt, Winston.Histogram(hst...; copy_remove(e, :bins)...))
# elseif d[:seriestype] == :bar
# elseif plotattributes[:seriestype] == :bar
# # fn = Winston.XXX
else
error("seriestype $(d[:seriestype]) not supported by Winston.")
error("seriestype $(plotattributes[:seriestype]) not supported by Winston.")
end
# markershape
if d[:markershape] != :none
Winston.add(wplt, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)..., color=getColor(d[:markercolor])))
if plotattributes[:markershape] != :none
Winston.add(wplt, Winston.Points(plotattributes[:x], plotattributes[:y]; copy_remove(e, :kind)..., color=getColor(plotattributes[:markercolor])))
end
# optionally add a regression line
d[:smooth] && d[:seriestype] != :histogram && addRegressionLineWinston(d, wplt)
plotattributes[:smooth] && plotattributes[:seriestype] != :histogram && addRegressionLineWinston(plotattributes, wplt)
# push!(plt.seriesargs, d)
# push!(plt.seriesargs, plotattributes)
# plt
end
@@ -192,17 +192,17 @@ const _winstonNames = KW(
:yscale => :ylog,
)
function _update_plot_object(plt::Plot{WinstonBackend}, d::KW)
function _update_plot_object(plt::Plot{WinstonBackend}, plotattributes::KW)
window, canvas, wplt = getWinstonItems(plt)
for k in (:xguide, :yguide, :title, :xlims, :ylims)
if haskey(d, k)
Winston.setattr(wplt, string(get(_winstonNames, k, k)), d[k])
if haskey(plotattributes, k)
Winston.setattr(wplt, string(get(_winstonNames, k, k)), plotattributes[k])
end
end
for k in (:xscale, :yscale)
if haskey(d, k)
islogscale = d[k] == :log10
if haskey(plotattributes, k)
islogscale = plotattributes[k] == :log10
Winston.setattr(wplt, (k == :xscale ? :xlog : :ylog), islogscale)
end
end
+14 -14
View File
@@ -7,22 +7,22 @@
const FuncOrFuncs = Union{Function, AVec{Function}}
all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(d, :seriestype, :none))
all3D(plotattributes::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(plotattributes, :seriestype, :none))
# missing
convertToAnyVector(v::Nothing, d::KW) = Any[nothing], nothing
convertToAnyVector(v::Nothing, plotattributes::KW) = Any[nothing], nothing
# fixed number of blank series
convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing
convertToAnyVector(n::Integer, plotattributes::KW) = Any[zeros(0) for i in 1:n], nothing
# numeric vector
convertToAnyVector(v::AVec{T}, d::KW) where {T<:Number} = Any[v], nothing
convertToAnyVector(v::AVec{T}, plotattributes::KW) where {T<:Number} = Any[v], nothing
# string vector
convertToAnyVector(v::AVec{T}, d::KW) where {T<:AbstractString} = Any[v], nothing
convertToAnyVector(v::AVec{T}, plotattributes::KW) where {T<:AbstractString} = Any[v], nothing
function convertToAnyVector(v::AMat, d::KW)
if all3D(d)
function convertToAnyVector(v::AMat, plotattributes::KW)
if all3D(plotattributes)
Any[Surface(v)]
else
Any[v[:,i] for i in 1:size(v,2)]
@@ -30,30 +30,30 @@ function convertToAnyVector(v::AMat, d::KW)
end
# function
convertToAnyVector(f::Function, d::KW) = Any[f], nothing
convertToAnyVector(f::Function, plotattributes::KW) = Any[f], nothing
# surface
convertToAnyVector(s::Surface, d::KW) = Any[s], nothing
convertToAnyVector(s::Surface, plotattributes::KW) = Any[s], nothing
# # vector of OHLC
# convertToAnyVector(v::AVec{OHLC}, d::KW) = Any[v], nothing
# convertToAnyVector(v::AVec{OHLC}, plotattributes::KW) = Any[v], nothing
# dates
convertToAnyVector(dts::AVec{D}, d::KW) where {D<:Union{Date,DateTime}} = Any[dts], nothing
convertToAnyVector(dts::AVec{D}, plotattributes::KW) where {D<:Union{Date,DateTime}} = Any[dts], nothing
# list of things (maybe other vectors, functions, or something else)
function convertToAnyVector(v::AVec, d::KW)
function convertToAnyVector(v::AVec, plotattributes::KW)
if all(x -> typeof(x) <: Number, v)
# all real numbers wrap the whole vector as one item
Any[convert(Vector{Float64}, v)], nothing
else
# something else... treat each element as an item
vcat(Any[convertToAnyVector(vi, d)[1] for vi in v]...), nothing
vcat(Any[convertToAnyVector(vi, plotattributes)[1] for vi in v]...), nothing
# Any[vi for vi in v], nothing
end
end
convertToAnyVector(t::Tuple, d::KW) = Any[t], nothing
convertToAnyVector(t::Tuple, plotattributes::KW) = Any[t], nothing
function convertToAnyVector(args...)
+13 -10
View File
@@ -52,7 +52,7 @@ the `z` argument to turn on series gradients.
[:(begin
y = rand(100)
plot(0:10:100,rand(11,4),lab="lines",w=3,palette=:grays,fill=0, α=0.6)
scatter!(y, zcolor=abs.(y.-0.5), m=(:heat,0.8,stroke(1,:green)), ms=10*abs.(y.-0.5).+4,
scatter!(y, zcolor=abs.(y.-0.5), m=(:heat,0.8,Plots.stroke(1,:green)), ms=10*abs.(y.-0.5).+4,
lab="grad")
end)]
),
@@ -66,6 +66,7 @@ the preprocessing step. You can also use shorthand functions: `title!`, `xaxis!`
`yaxis!`, `xlabel!`, `ylabel!`, `xlims!`, `ylims!`, `xticks!`, `yticks!`
""",
[:(begin
using Statistics
y = rand(20,3)
plot(y, xaxis=("XLABEL",(-5,30),0:2:20,:flip), background_color = RGB(0.2,0.2,0.2),
leg=false)
@@ -85,8 +86,8 @@ yaxis!("YLABEL", :log10)
PlotExample("Images",
"Plot an image. y-axis is set to flipped",
[:(begin
import FileIO
img = FileIO.load(Pkg.dir("PlotReferenceImages","Plots","pyplot","0.7.0","ref1.png"))
import FileIO, PlotReferenceImages
img = FileIO.load(joinpath(dirname(pathof(PlotReferenceImages)), "..", "Plots","pyplot","0.7.0","ref1.png"))
plot(img)
end)]
),
@@ -102,7 +103,7 @@ series.
""",
[:(begin
ys = Vector[rand(10), rand(20)]
plot(ys, color=[:black :orange], line=(:dot,4), marker=([:hex :d],12,0.8,stroke(3,:gray)))
plot(ys, color=[:black :orange], line=(:dot,4), marker=([:hex :d],12,0.8,Plots.stroke(3,:gray)))
end)]
),
@@ -202,7 +203,8 @@ plot(Plots.fakedata(100,10), layout=4, palette=[:grays :blues :heat :lightrainbo
PlotExample("",
"",
[:(begin
Random.srand(111)
using Random
Random.seed!(111)
plot!(Plots.fakedata(100,10))
end)]
),
@@ -295,7 +297,7 @@ PlotExample("3D",
x = ts .* map(cos,ts)
y = 0.1ts .* map(sin,ts)
z = 1:n
plot(x, y, z, zcolor=reverse(z), m=(10,0.8,:blues,stroke(0)), leg=false, cbar=true, w=5)
plot(x, y, z, zcolor=reverse(z), m=(10,0.8,:blues,Plots.stroke(0)), leg=false, cbar=true, w=5)
plot!(zeros(n),zeros(n),1:n, w=10)
end)]
),
@@ -382,8 +384,9 @@ various different nonzero values, a colorbar is added. The colorbar can be disab
`legend = nothing`.
""",
[:(begin
a = spdiagm((ones(50), ones(49), ones(49), ones(40), ones(40)),(0, 1, -1, 10, -10))
b = spdiagm((1:50, 1:49, 1:49, 1:40, 1:40),(0, 1, -1, 10, -10))
using SparseArrays
a = spdiagm(0 => ones(50), 1 => ones(49), -1 => ones(49), 10 => ones(40), -10 => ones(40))
b = spdiagm(0 => 1:50, 1 => 1:49, -1 => 1:49, 10 => 1:40, -10 => 1:40)
plot(spy(a), spy(b), title = ["Unique nonzeros" "Different nonzeros"])
end)]
),
@@ -411,7 +414,7 @@ attribute. The default framestyle is `:axes`.
scatter(fill(randn(10), 6), fill(randn(10), 6),
framestyle = [:box :semi :origin :zerolines :grid :none],
title = [":box" ":semi" ":origin" ":zerolines" ":grid" ":none"],
color = RowVector(1:6), layout = 6, label = "", markerstrokewidth = 0,
color = permutedims(1:6), layout = 6, label = "", markerstrokewidth = 0,
ticks = -2:2)
end)]
),
@@ -427,7 +430,7 @@ each line segment or marker in the plot.
x = t .* cos.(θ)
y = t .* sin.(θ)
p1 = plot(x, y, line_z=t, linewidth=3, legend=false)
p2 = scatter(x, y, marker_z=t, color=:bluesreds, legend=false)
p2 = scatter(x, y, marker_z=(x,y)->x+y, color=:bluesreds, legend=false)
plot(p1, p2)
end)]
),
+18 -1
View File
@@ -1,9 +1,26 @@
function __init__()
if isdefined(Main, :PLOTS_DEFAULTS)
if haskey(Main.PLOTS_DEFAULTS, :theme)
theme(Main.PLOTS_DEFAULTS[:theme])
end
for (k,v) in Main.PLOTS_DEFAULTS
k == :theme || default(k, v)
end
end
pushdisplay(PlotsDisplay())
atreplinit(i -> begin
if PlotDisplay() in Base.Multimedia.displays
popdisplay(PlotsDisplay())
end
pushdisplay(PlotsDisplay())
end)
include(joinpath(@__DIR__, "backends", "plotly.jl"))
include(joinpath(@__DIR__, "backends", "gr.jl"))
include(joinpath(@__DIR__, "backends", "web.jl"))
@require GLVisualize = "4086de5b-f4b6-55f3-abb0-b8c73827585f" include(joinpath(@__DIR__, "backends", "gr.jl"))
@require GLVisualize = "4086de5b-f4b6-55f3-abb0-b8c73827585f" include(joinpath(@__DIR__, "backends", "glvisualize.jl"))
@require HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" include(joinpath(@__DIR__, "backends", "hdf5.jl"))
@require InspectDR = "d0351b0e-4b05-5898-87b3-e2a8edfddd1d" include(joinpath(@__DIR__, "backends", "inspectdr.jl"))
@require PGFPlots = "3b7a836e-365b-5785-a47d-02c71176b4aa" include(joinpath(@__DIR__, "backends", "pgfplots.jl"))
+4 -4
View File
@@ -464,12 +464,12 @@ end
# constructors
# pass the layout arg through
function layout_args(d::KW)
layout_args(get(d, :layout, default(:layout)))
function layout_args(plotattributes::KW)
layout_args(get(plotattributes, :layout, default(:layout)))
end
function layout_args(d::KW, n_override::Integer)
layout, n = layout_args(get(d, :layout, n_override))
function layout_args(plotattributes::KW, n_override::Integer)
layout, n = layout_args(get(plotattributes, :layout, n_override))
if n != n_override
error("When doing layout, n ($n) != n_override ($(n_override)). You're probably trying to force existing plots into a layout that doesn't fit them.")
end
+2 -7
View File
@@ -145,11 +145,6 @@ function Base.display(::PlotsDisplay, plt::Plot)
_display(plt)
end
# override the REPL display to open a gui window
using REPL
Base.display(::REPL.REPLDisplay, ::MIME"text/plain", plt::Plot) = gui(plt)
_do_plot_show(plt, showval::Bool) = showval && gui(plt)
function _do_plot_show(plt, showval::Symbol)
showval == :gui && gui(plt)
@@ -173,10 +168,10 @@ function _show(io::IO, ::MIME"text/html", plt::Plot)
output_type = get(_best_html_output_type, backend_name(plt.backend), :svg)
end
if output_type == :png
# info("writing png to html output")
# @info("writing png to html output")
print(io, "<img src=\"data:image/png;base64,", base64encode(show, MIME("image/png"), plt), "\" />")
elseif output_type == :svg
# info("writing svg to html output")
# @info("writing svg to html output")
show(io, MIME("image/svg+xml"), plt)
elseif output_type == :txt
show(io, MIME("text/plain"), plt)
+64 -64
View File
@@ -7,44 +7,44 @@ function command_idx(kw_list::AVec{KW}, kw::KW)
Int(kw[:series_plotindex]) - Int(kw_list[1][:series_plotindex]) + 1
end
function _expand_seriestype_array(d::KW, args)
sts = get(d, :seriestype, :path)
function _expand_seriestype_array(plotattributes::KW, args)
sts = get(plotattributes, :seriestype, :path)
if typeof(sts) <: AbstractArray
delete!(d, :seriestype)
delete!(plotattributes, :seriestype)
rd = Vector{RecipeData}(undef, size(sts, 1))
for r in 1:size(sts, 1)
dc = copy(d)
dc = copy(plotattributes)
dc[:seriestype] = sts[r:r,:]
rd[r] = RecipeData(dc, args)
end
rd
else
RecipeData[RecipeData(copy(d), args)]
RecipeData[RecipeData(copy(plotattributes), args)]
end
end
function _preprocess_args(d::KW, args, still_to_process::Vector{RecipeData})
function _preprocess_args(plotattributes::KW, args, still_to_process::Vector{RecipeData})
# the grouping mechanism is a recipe on a GroupBy object
# we simply add the GroupBy object to the front of the args list to allow
# the recipe to be applied
if haskey(d, :group)
args = (extractGroupArgs(d[:group], args...), args...)
if haskey(plotattributes, :group)
args = (extractGroupArgs(plotattributes[:group], args...), args...)
end
# if we were passed a vector/matrix of seriestypes and there's more than one row,
# we want to duplicate the inputs, once for each seriestype row.
if !isempty(args)
append!(still_to_process, _expand_seriestype_array(d, args))
append!(still_to_process, _expand_seriestype_array(plotattributes, args))
end
# remove subplot and axis args from d... they will be passed through in the kw_list
# remove subplot and axis args from plotattributes... they will be passed through in the kw_list
if !isempty(args)
for (k,v) in d
for (k,v) in plotattributes
for defdict in (_subplot_defaults,
_axis_defaults,
_axis_defaults_byletter)
if haskey(defdict, k)
delete!(d, k)
delete!(plotattributes, k)
end
end
end
@@ -57,9 +57,9 @@ end
# user recipes
function _process_userrecipes(plt::Plot, d::KW, args)
function _process_userrecipes(plt::Plot, plotattributes::KW, args)
still_to_process = RecipeData[]
args = _preprocess_args(d, args, still_to_process)
args = _preprocess_args(plotattributes, args, still_to_process)
# for plotting recipes, swap out the args and update the parameter dictionary
# we are keeping a stack of series that still need to be processed.
@@ -80,20 +80,20 @@ function _process_userrecipes(plt::Plot, d::KW, args)
if isempty(next_series.args)
_process_userrecipe(plt, kw_list, next_series)
else
rd_list = RecipesBase.apply_recipe(next_series.d, next_series.args...)
rd_list = RecipesBase.apply_recipe(next_series.plotattributes, next_series.args...)
prepend!(still_to_process,rd_list)
end
end
# don't allow something else to handle it
d[:smooth] = false
plotattributes[:smooth] = false
kw_list
end
function _process_userrecipe(plt::Plot, kw_list::Vector{KW}, recipedata::RecipeData)
# when the arg tuple is empty, that means there's nothing left to recursively
# process... finish up and add to the kw_list
kw = recipedata.d
kw = recipedata.plotattributes
preprocessArgs!(kw)
_preprocess_userrecipe(kw)
warnOnUnsupported_scales(plt.backend, kw)
@@ -117,12 +117,12 @@ function _preprocess_userrecipe(kw::KW)
# map marker_z if it's a Function
if isa(get(kw, :marker_z, nothing), Function)
# TODO: should this take y and/or z as arguments?
kw[:marker_z] = map(kw[:marker_z], kw[:x], kw[:y], kw[:z])
kw[:marker_z] = isa(kw[:z], Nothing) ? map(kw[:marker_z], kw[:x], kw[:y]) : map(kw[:marker_z], kw[:x], kw[:y], kw[:z])
end
# map line_z if it's a Function
if isa(get(kw, :line_z, nothing), Function)
kw[:line_z] = map(kw[:line_z], kw[:x], kw[:y], kw[:z])
kw[:line_z] = isa(kw[:z], Nothing) ? map(kw[:line_z], kw[:x], kw[:y]) : map(kw[:line_z], kw[:x], kw[:y], kw[:z])
end
# convert a ribbon into a fillrange
@@ -183,11 +183,11 @@ function _process_plotrecipe(plt::Plot, kw::KW, kw_list::Vector{KW}, still_to_pr
st = kw[:seriestype] = get(_typeAliases, st, st)
datalist = RecipesBase.apply_recipe(kw, Val{st}, plt)
for data in datalist
preprocessArgs!(data.d)
if data.d[:seriestype] == st
error("Plot recipe $st returned the same seriestype: $(data.d)")
preprocessArgs!(data.plotattributes)
if data.plotattributes[:seriestype] == st
error("Plot recipe $st returned the same seriestype: $(data.plotattributes)")
end
push!(still_to_process, data.d)
push!(still_to_process, data.plotattributes)
end
catch err
if isa(err, MethodError)
@@ -203,14 +203,14 @@ end
# ------------------------------------------------------------------
# setup plot and subplot
function _plot_setup(plt::Plot, d::KW, kw_list::Vector{KW})
function _plot_setup(plt::Plot, plotattributes::KW, kw_list::Vector{KW})
# merge in anything meant for the Plot
for kw in kw_list, (k,v) in kw
haskey(_plot_defaults, k) && (d[k] = pop!(kw, k))
haskey(_plot_defaults, k) && (plotattributes[k] = pop!(kw, k))
end
# TODO: init subplots here
_update_plot_args(plt, d)
_update_plot_args(plt, plotattributes)
if !plt.init
plt.o = Base.invokelatest(_create_backend_figure, plt)
@@ -252,7 +252,7 @@ function _plot_setup(plt::Plot, d::KW, kw_list::Vector{KW})
plt[:inset_subplots] = nothing
end
function _subplot_setup(plt::Plot, d::KW, kw_list::Vector{KW})
function _subplot_setup(plt::Plot, plotattributes::KW, kw_list::Vector{KW})
# we'll keep a map of subplot to an attribute override dict.
# Subplot/Axis attributes set by a user/series recipe apply only to the
# Subplot object which they belong to.
@@ -289,8 +289,8 @@ function _subplot_setup(plt::Plot, d::KW, kw_list::Vector{KW})
# override subplot/axis args. `sp_attrs` take precendence
for (idx,sp) in enumerate(plt.subplots)
attr = if !haskey(d, :subplot) || d[:subplot] == idx
merge(d, get(sp_attrs, sp, KW()))
attr = if !haskey(plotattributes, :subplot) || plotattributes[:subplot] == idx
merge(plotattributes, get(sp_attrs, sp, KW()))
else
get(sp_attrs, sp, KW())
end
@@ -303,13 +303,13 @@ end
# getting ready to add the series... last update to subplot from anything
# that might have been added during series recipes
function _prepare_subplot(plt::Plot{T}, d::KW) where T
st::Symbol = d[:seriestype]
sp::Subplot{T} = d[:subplot]
function _prepare_subplot(plt::Plot{T}, plotattributes::KW) where T
st::Symbol = plotattributes[:seriestype]
sp::Subplot{T} = plotattributes[:subplot]
sp_idx = get_subplot_index(plt, sp)
_update_subplot_args(plt, sp, d, sp_idx, true)
_update_subplot_args(plt, sp, plotattributes, sp_idx, true)
st = _override_seriestype_check(d, st)
st = _override_seriestype_check(plotattributes, st)
# change to a 3d projection for this subplot?
if is3d(st)
@@ -327,28 +327,28 @@ end
# ------------------------------------------------------------------
# series types
function _override_seriestype_check(d::KW, st::Symbol)
function _override_seriestype_check(plotattributes::KW, st::Symbol)
# do we want to override the series type?
if !is3d(st) && !(st in (:contour,:contour3d))
z = d[:z]
if !isa(z, Nothing) && (size(d[:x]) == size(d[:y]) == size(z))
z = plotattributes[:z]
if !isa(z, Nothing) && (size(plotattributes[:x]) == size(plotattributes[:y]) == size(z))
st = (st == :scatter ? :scatter3d : :path3d)
d[:seriestype] = st
plotattributes[:seriestype] = st
end
end
st
end
function _prepare_annotations(sp::Subplot, d::KW)
function _prepare_annotations(sp::Subplot, plotattributes::KW)
# strip out series annotations (those which are based on series x/y coords)
# and add them to the subplot attr
sp_anns = annotations(sp[:annotations])
# series_anns = annotations(pop!(d, :series_annotations, []))
# series_anns = annotations(pop!(plotattributes, :series_annotations, []))
# if isa(series_anns, SeriesAnnotations)
# series_anns.x = d[:x]
# series_anns.y = d[:y]
# series_anns.x = plotattributes[:x]
# series_anns.y = plotattributes[:y]
# elseif length(series_anns) > 0
# x, y = d[:x], d[:y]
# x, y = plotattributes[:x], plotattributes[:y]
# nx, ny, na = map(length, (x,y,series_anns))
# n = max(nx, ny, na)
# series_anns = [(x[mod1(i,nx)], y[mod1(i,ny)], text(series_anns[mod1(i,na)])) for i=1:n]
@@ -356,14 +356,14 @@ function _prepare_annotations(sp::Subplot, d::KW)
# sp.attr[:annotations] = vcat(sp_anns, series_anns)
end
function _expand_subplot_extrema(sp::Subplot, d::KW, st::Symbol)
function _expand_subplot_extrema(sp::Subplot, plotattributes::KW, st::Symbol)
# adjust extrema and discrete info
if st == :image
xmin, xmax = ignorenan_extrema(d[:x]); ymin, ymax = ignorenan_extrema(d[:y])
xmin, xmax = ignorenan_extrema(plotattributes[:x]); ymin, ymax = ignorenan_extrema(plotattributes[:y])
expand_extrema!(sp[:xaxis], (xmin, xmax))
expand_extrema!(sp[:yaxis], (ymin, ymax))
elseif !(st in (:pie, :histogram, :bins2d, :histogram2d))
expand_extrema!(sp, d)
expand_extrema!(sp, plotattributes)
end
# expand for zerolines (axes through origin)
if sp[:framestyle] in (:origin, :zerolines)
@@ -372,10 +372,10 @@ function _expand_subplot_extrema(sp::Subplot, d::KW, st::Symbol)
end
end
function _add_the_series(plt, sp, d)
warnOnUnsupported_args(plt.backend, d)
warnOnUnsupported(plt.backend, d)
series = Series(d)
function _add_the_series(plt, sp, plotattributes)
warnOnUnsupported_args(plt.backend, plotattributes)
warnOnUnsupported(plt.backend, plotattributes)
series = Series(plotattributes)
push!(plt.series_list, series)
push!(sp.series_list, series)
_series_added(plt, series)
@@ -385,36 +385,36 @@ end
# this method recursively applies series recipes when the seriestype is not supported
# natively by the backend
function _process_seriesrecipe(plt::Plot, d::KW)
function _process_seriesrecipe(plt::Plot, plotattributes::KW)
# replace seriestype aliases
st = Symbol(d[:seriestype])
st = d[:seriestype] = get(_typeAliases, st, st)
st = Symbol(plotattributes[:seriestype])
st = plotattributes[:seriestype] = get(_typeAliases, st, st)
# shapes shouldn't have fillrange set
if d[:seriestype] == :shape
d[:fillrange] = nothing
if plotattributes[:seriestype] == :shape
plotattributes[:fillrange] = nothing
end
# if it's natively supported, finalize processing and pass along to the backend, otherwise recurse
if is_seriestype_supported(st)
sp = _prepare_subplot(plt, d)
_prepare_annotations(sp, d)
_expand_subplot_extrema(sp, d, st)
_update_series_attributes!(d, plt, sp)
_add_the_series(plt, sp, d)
sp = _prepare_subplot(plt, plotattributes)
_prepare_annotations(sp, plotattributes)
_expand_subplot_extrema(sp, plotattributes, st)
_update_series_attributes!(plotattributes, plt, sp)
_add_the_series(plt, sp, plotattributes)
else
# get a sub list of series for this seriestype
datalist = RecipesBase.apply_recipe(d, Val{st}, d[:x], d[:y], d[:z])
datalist = RecipesBase.apply_recipe(plotattributes, Val{st}, plotattributes[:x], plotattributes[:y], plotattributes[:z])
# assuming there was no error, recursively apply the series recipes
for data in datalist
if isa(data, RecipeData)
preprocessArgs!(data.d)
if data.d[:seriestype] == st
preprocessArgs!(data.plotattributes)
if data.plotattributes[:seriestype] == st
error("The seriestype didn't change in series recipe $st. This will cause a StackOverflow.")
end
_process_seriesrecipe(plt, data.d)
_process_seriesrecipe(plt, data.plotattributes)
else
@warn("Unhandled recipe: $(data)")
break
+29 -29
View File
@@ -48,20 +48,20 @@ as a String to look up its docstring; e.g. `plotattr("seriestype")`.
"""
function plot(args...; kw...)
# this creates a new plot with args/kw and sets it to be the current plot
d = KW(kw)
preprocessArgs!(d)
plotattributes = KW(kw)
preprocessArgs!(plotattributes)
# create an empty Plot then process
plt = Plot()
# plt.user_attr = d
_plot!(plt, d, args)
# plt.user_attr = plotattributes
_plot!(plt, plotattributes, args)
end
# build a new plot from existing plots
# note: we split into plt1 and plts_tail so we can dispatch correctly
function plot(plt1::Plot, plts_tail::Plot...; kw...)
d = KW(kw)
preprocessArgs!(d)
plotattributes = KW(kw)
preprocessArgs!(plotattributes)
# build our plot vector from the args
n = length(plts_tail) + 1
@@ -72,7 +72,7 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...)
end
# compute the layout
layout = layout_args(d, n)[1]
layout = layout_args(plotattributes, n)[1]
num_sp = sum([length(p.subplots) for p in plts])
# create a new plot object, with subplot list/map made of existing subplots.
@@ -83,21 +83,21 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...)
# TODO: build the user_attr dict by creating "Any matrices" for the args of each subplot
# TODO: replace this with proper processing from a merged user_attr KW
# update plot args, first with existing plots, then override with d
# update plot args, first with existing plots, then override with plotattributes
for p in plts
_update_plot_args(plt, copy(p.attr))
plt.n += p.n
end
_update_plot_args(plt, d)
_update_plot_args(plt, plotattributes)
# pass new plot to the backend
plt.o = _create_backend_figure(plt)
plt.init = true
series_attr = KW()
for (k,v) in d
for (k,v) in plotattributes
if haskey(_series_defaults, k)
series_attr[k] = pop!(d,k)
series_attr[k] = pop!(plotattributes,k)
end
end
@@ -118,8 +118,8 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...)
sp.plt = plt
sp.attr[:subplot_index] = idx
for series in serieslist
merge!(series.d, series_attr)
_add_defaults!(series.d, plt, sp, cmdidx)
merge!(series.plotattributes, series_attr)
_add_defaults!(series.plotattributes, plt, sp, cmdidx)
push!(plt.series_list, series)
_series_added(plt, series)
cmdidx += 1
@@ -128,12 +128,12 @@ function plot(plt1::Plot, plts_tail::Plot...; kw...)
# first apply any args for the subplots
for (idx,sp) in enumerate(plt.subplots)
_update_subplot_args(plt, sp, d, idx, false)
_update_subplot_args(plt, sp, plotattributes, idx, false)
end
# finish up
current(plt)
_do_plot_show(plt, get(d, :show, default(:show)))
_do_plot_show(plt, get(plotattributes, :show, default(:show)))
plt
end
@@ -152,10 +152,10 @@ end
# this adds to a specific plot... most plot commands will flow through here
function plot!(plt::Plot, args...; kw...)
d = KW(kw)
preprocessArgs!(d)
# merge!(plt.user_attr, d)
_plot!(plt, d, args)
plotattributes = KW(kw)
preprocessArgs!(plotattributes)
# merge!(plt.user_attr, plotattributes)
_plot!(plt, plotattributes, args)
end
# -------------------------------------------------------------------------------
@@ -163,8 +163,8 @@ end
# this is the core plotting function. recursively apply recipes to build
# a list of series KW dicts.
# note: at entry, we only have those preprocessed args which were passed in... no default values yet
function _plot!(plt::Plot, d::KW, args::Tuple)
d[:plot_object] = plt
function _plot!(plt::Plot, plotattributes::KW, args::Tuple)
plotattributes[:plot_object] = plt
if !isempty(args) && !isdefined(Main, :StatPlots) &&
first(split(string(typeof(args[1])), ".")) == "DataFrames"
@@ -175,9 +175,9 @@ function _plot!(plt::Plot, d::KW, args::Tuple)
# "USER RECIPES"
# --------------------------------
kw_list = _process_userrecipes(plt, d, args)
kw_list = _process_userrecipes(plt, plotattributes, args)
# info(1)
# @info(1)
# map(DD, kw_list)
@@ -196,14 +196,14 @@ function _plot!(plt::Plot, d::KW, args::Tuple)
_process_plotrecipe(plt, next_kw, kw_list, still_to_process)
end
# info(2)
# @info(2)
# map(DD, kw_list)
# --------------------------------
# Plot/Subplot/Layout setup
# --------------------------------
_plot_setup(plt, d, kw_list)
_subplot_setup(plt, d, kw_list)
_plot_setup(plt, plotattributes, kw_list)
_subplot_setup(plt, plotattributes, kw_list)
# !!! note: At this point, kw_list is fully decomposed into individual series... one KW per series. !!!
# !!! The next step is to recursively apply series recipes until the backend supports that series type !!!
@@ -212,7 +212,7 @@ function _plot!(plt::Plot, d::KW, args::Tuple)
# "SERIES RECIPES"
# --------------------------------
# info(3)
# @info(3)
# map(DD, kw_list)
for kw in kw_list
@@ -283,11 +283,11 @@ end
function plot(sp::Subplot, args...; kw...)
plt = sp.plt
plot(plt, args...; kw..., subplot = findfirst(plt.subplots, sp))
plot(plt, args...; kw..., subplot = findfirst(isequal(sp), plt.subplots))
end
function plot!(sp::Subplot, args...; kw...)
plt = sp.plt
plot!(plt, args...; kw..., subplot = findfirst(plt.subplots, sp))
plot!(plt, args...; kw..., subplot = findfirst(isequal(sp), plt.subplots))
end
# --------------------------------------------------------------------
+9 -6
View File
@@ -40,23 +40,26 @@ function plotattr(attribute::AbstractString)
error("There is no attribute named $attribute")
end
printnothing(x) = x
printnothing(x::Nothing) = "nothing"
function plotattr(attrtype::Symbol, attribute::AbstractString)
in(attrtype, keys(_attribute_defaults)) || ArgumentError("`attrtype` must match one of $(attrtypes())")
attribute = Symbol(lookup_aliases(attrtype, attribute))
desc = get(_arg_desc, attribute, "")
first_period_idx = findfirst(desc, '.')
first_period_idx = findfirst(isequal('.'), desc)
typedesc = desc[1:first_period_idx-1]
desc = strip(desc[first_period_idx+1:end])
als = keys(filter((_,v)->v==attribute, _keyAliases)) |> collect |> sort
als = keys(filter(x->x[2]==attribute, _keyAliases)) |> collect |> sort
als = join(map(string,als), ", ")
def = _attribute_defaults[attrtype][attribute]
# Looks up the different elements and plots them
println("$attribute ", typedesc == "" ? "" : "{$typedesc}", "\n",
als == "" ? "" : "$als\n",
"\n$desc\n",
"$(attrtype) attribute, ", def == "" ? "" : " default: $def")
println("$(printnothing(attribute)) ", typedesc == "" ? "" : "{$(printnothing(typedesc))}", "\n",
als == "" ? "" : "$(printnothing(als))\n",
"\n$(printnothing(desc))\n",
"$(printnothing(attrtype)) attribute, ", def == "" ? "" : " default: $(printnothing(def))")
end
+48 -50
View File
@@ -47,7 +47,7 @@ end
num_series(x::AMat) = size(x,2)
num_series(x) = 1
RecipesBase.apply_recipe(d::KW, ::Type{T}, plt::AbstractPlot) where {T} = throw(MethodError("Unmatched plot recipe: $T"))
RecipesBase.apply_recipe(plotattributes::KW, ::Type{T}, plt::AbstractPlot) where {T} = throw(MethodError("Unmatched plot recipe: $T"))
# ---------------------------------------------------------------------------
@@ -277,7 +277,7 @@ end
fr = plotattributes[:fillrange]
newfr = fr != nothing ? zeros(0) : nothing
newz = z != nothing ? zeros(0) : nothing
# lz = d[:line_z]
# lz = plotattributes[:line_z]
# newlz = lz != nothing ? zeros(0) : nothing
# for each line segment (point series with no NaNs), convert it into a bezier curve
@@ -313,9 +313,9 @@ end
end
# if lz != nothing
# # line_z := newlz
# linecolor := (isa(d[:linecolor], ColorGradient) ? d[:linecolor] : cgrad())
# linecolor := (isa(plotattributes[:linecolor], ColorGradient) ? plotattributes[:linecolor] : cgrad())
# end
# Plots.DD(d)
# Plots.DD(plotattributes)
()
end
@deps curves path
@@ -453,16 +453,16 @@ function _preprocess_binbarlike_weights(::Type{T}, w, wscale::Symbol) where T<:A
w_adj, baseline
end
function _preprocess_barlike(d, x, y)
xscale = get(d, :xscale, :identity)
yscale = get(d, :yscale, :identity)
function _preprocess_barlike(plotattributes, x, y)
xscale = get(plotattributes, :xscale, :identity)
yscale = get(plotattributes, :yscale, :identity)
weights, baseline = _preprocess_binbarlike_weights(float(eltype(y)), y, yscale)
x, weights, xscale, yscale, baseline
end
function _preprocess_binlike(d, x, y)
xscale = get(d, :xscale, :identity)
yscale = get(d, :yscale, :identity)
function _preprocess_binlike(plotattributes, x, y)
xscale = get(plotattributes, :xscale, :identity)
yscale = get(plotattributes, :yscale, :identity)
T = float(promote_type(eltype(x), eltype(y)))
edge = T.(x)
weights, baseline = _preprocess_binbarlike_weights(T, y, yscale)
@@ -781,11 +781,11 @@ end
# ---------------------------------------------------------------------------
# Error Bars
function error_style!(d::KW)
d[:seriestype] = :path
d[:linecolor] = d[:markerstrokecolor]
d[:linewidth] = d[:markerstrokewidth]
d[:label] = ""
function error_style!(plotattributes::KW)
plotattributes[:seriestype] = :path
plotattributes[:linecolor] = plotattributes[:markerstrokecolor]
plotattributes[:linewidth] = plotattributes[:markerstrokewidth]
plotattributes[:label] = ""
end
# if we're passed a tuple of vectors, convert to a vector of tuples
@@ -842,16 +842,16 @@ end
# ---------------------------------------------------------------------------
# quiver
# function apply_series_recipe(d::KW, ::Type{Val{:quiver}})
function quiver_using_arrows(d::KW)
d[:label] = ""
d[:seriestype] = :path
if !isa(d[:arrow], Arrow)
d[:arrow] = arrow()
# function apply_series_recipe(plotattributes::KW, ::Type{Val{:quiver}})
function quiver_using_arrows(plotattributes::KW)
plotattributes[:label] = ""
plotattributes[:seriestype] = :path
if !isa(plotattributes[:arrow], Arrow)
plotattributes[:arrow] = arrow()
end
velocity = error_zipit(d[:quiver])
xorig, yorig = d[:x], d[:y]
velocity = error_zipit(plotattributes[:quiver])
xorig, yorig = plotattributes[:x], plotattributes[:y]
# for each point, we create an arrow of velocity vi, translated to the x/y coordinates
x, y = zeros(0), zeros(0)
@@ -877,17 +877,17 @@ function quiver_using_arrows(d::KW)
nanappend!(y, [yi, yi+vy, NaN])
end
d[:x], d[:y] = x, y
# KW[d]
plotattributes[:x], plotattributes[:y] = x, y
# KW[plotattributes]
end
# function apply_series_recipe(d::KW, ::Type{Val{:quiver}})
function quiver_using_hack(d::KW)
d[:label] = ""
d[:seriestype] = :shape
# function apply_series_recipe(plotattributes::KW, ::Type{Val{:quiver}})
function quiver_using_hack(plotattributes::KW)
plotattributes[:label] = ""
plotattributes[:seriestype] = :shape
velocity = error_zipit(d[:quiver])
xorig, yorig = d[:x], d[:y]
velocity = error_zipit(plotattributes[:quiver])
xorig, yorig = plotattributes[:x], plotattributes[:y]
# for each point, we create an arrow of velocity vi, translated to the x/y coordinates
pts = P2[]
@@ -923,11 +923,11 @@ function quiver_using_hack(d::KW)
nanappend!(pts, P2[p, ppv-U1, ppv-U1+U2, ppv, ppv-U1-U2, ppv-U1])
end
d[:x], d[:y] = Plots.unzip(pts[2:end])
# KW[d]
plotattributes[:x], plotattributes[:y] = Plots.unzip(pts[2:end])
# KW[plotattributes]
end
# function apply_series_recipe(d::KW, ::Type{Val{:quiver}})
# function apply_series_recipe(plotattributes::KW, ::Type{Val{:quiver}})
@recipe function f(::Type{Val{:quiver}}, x, y, z)
if :arrow in supported_attrs()
quiver_using_arrows(plotattributes)
@@ -1024,10 +1024,6 @@ end
@assert length(g.args) == 1 && typeof(g.args[1]) <: AbstractMatrix
seriestype := :spy
mat = g.args[1]
if length(unique(mat[mat .!= 0])) < 2
legend --> nothing
seriescolor --> cgrad([invisible(), fg_color(plotattributes)])
end
n,m = size(mat)
Plots.SliceIt, 1:m, 1:n, Surface(mat)
end
@@ -1035,21 +1031,23 @@ end
@recipe function f(::Type{Val{:spy}}, x,y,z)
yflip := true
aspect_ratio := 1
rs, cs, zs = findnz(z.surf)
newz = fill(NaN, size(z)...)
for i in eachindex(zs)
newz[rs[i],cs[i]] = zs[i]
xlim := ignorenan_extrema(cs)
ylim := ignorenan_extrema(rs)
if plotattributes[:markershape] == :none
markershape := :circle
end
seriestype := :heatmap
if plotattributes[:markersize] == default(:markersize)
markersize := 1
end
markerstrokewidth := 0
marker_z := zs
label := ""
x := cs
y := rs
z := nothing
seriestype := :scatter
grid --> false
framestyle --> :box
x := x
y := y
z := Surface(newz)
()
end
+41 -34
View File
@@ -8,59 +8,66 @@
const FuncOrFuncs{F} = Union{F, Vector{F}, Matrix{F}}
all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image, :plots_heatmap), get(d, :seriestype, :none))
all3D(plotattributes::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image, :plots_heatmap), get(plotattributes, :seriestype, :none))
# unknown
convertToAnyVector(x, d::KW) = error("No user recipe defined for $(typeof(x))")
convertToAnyVector(x, plotattributes::KW) = error("No user recipe defined for $(typeof(x))")
# missing
convertToAnyVector(v::Nothing, d::KW) = Any[nothing], nothing
convertToAnyVector(v::Nothing, plotattributes::KW) = Any[nothing], nothing
# fixed number of blank series
convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing
convertToAnyVector(n::Integer, plotattributes::KW) = Any[zeros(0) for i in 1:n], nothing
# numeric vector
convertToAnyVector(v::AVec{T}, d::KW) where {T<:Number} = Any[v], nothing
convertToAnyVector(v::AVec{T}, plotattributes::KW) where {T<:Number} = Any[v], nothing
convertToAnyVector(v::AVec{Union{Missing, T}}, plotattributes::KW) where {T<:Number} = Any[replace(v, missing => NaN)], nothing
# string vector
convertToAnyVector(v::AVec{T}, d::KW) where {T<:AbstractString} = Any[v], nothing
convertToAnyVector(v::AVec{T}, plotattributes::KW) where {T<:AbstractString} = Any[v], nothing
convertToAnyVector(v::AVec{Union{Missing, T}}, plotattributes::KW) where {T<:AbstractString} = Any[replace(v, missing => "")], nothing
function convertToAnyVector(v::AMat, d::KW)
if all3D(d)
function convertToAnyVector(v::AMat, plotattributes::KW)
v = handlemissings(v)
if all3D(plotattributes)
Any[Surface(v)]
else
Any[v[:,i] for i in 1:size(v,2)]
end, nothing
end
handlemissings(v::AMat) = v
handlemissings(v::AMat{T}) where T <: Number = replace(v, missing => NaN)
handlemissings(v::AMat{T}) where T <: String = replace(v, missing => "")
# function
convertToAnyVector(f::Function, d::KW) = Any[f], nothing
convertToAnyVector(f::Function, plotattributes::KW) = Any[f], nothing
# surface
convertToAnyVector(s::Surface, d::KW) = Any[s], nothing
convertToAnyVector(s::Surface, plotattributes::KW) = Any[s], nothing
# volume
convertToAnyVector(v::Volume, d::KW) = Any[v], nothing
convertToAnyVector(v::Volume, plotattributes::KW) = Any[v], nothing
# # vector of OHLC
# convertToAnyVector(v::AVec{OHLC}, d::KW) = Any[v], nothing
# convertToAnyVector(v::AVec{OHLC}, plotattributes::KW) = Any[v], nothing
# # dates
convertToAnyVector(dts::AVec{D}, d::KW) where {D<:Union{Date,DateTime}} = Any[dts], nothing
convertToAnyVector(dts::AVec{D}, plotattributes::KW) where {D<:Union{Date,DateTime}} = Any[dts], nothing
# list of things (maybe other vectors, functions, or something else)
function convertToAnyVector(v::AVec, d::KW)
function convertToAnyVector(v::AVec, plotattributes::KW)
if all(x -> typeof(x) <: Number, v)
# all real numbers wrap the whole vector as one item
Any[convert(Vector{Float64}, v)], nothing
else
# something else... treat each element as an item
vcat(Any[convertToAnyVector(vi, d)[1] for vi in v]...), nothing
vcat(Any[convertToAnyVector(vi, plotattributes)[1] for vi in v]...), nothing
# Any[vi for vi in v], nothing
end
end
convertToAnyVector(t::Tuple, d::KW) = Any[t], nothing
convertToAnyVector(t::Tuple, plotattributes::KW) = Any[t], nothing
function convertToAnyVector(args...)
@@ -180,14 +187,14 @@ end
# this should catch unhandled "series recipes" and error with a nice message
@recipe f(::Type{V}, x, y, z) where {V<:Val} = error("The backend must not support the series type $V, and there isn't a series recipe defined.")
_apply_type_recipe(d, v) = RecipesBase.apply_recipe(d, typeof(v), v)[1].args[1]
_apply_type_recipe(plotattributes, v) = RecipesBase.apply_recipe(plotattributes, typeof(v), v)[1].args[1]
# Handle type recipes when the recipe is defined on the elements.
# This sort of recipe should return a pair of functions... one to convert to number,
# and one to format tick values.
function _apply_type_recipe(d, v::AbstractArray)
function _apply_type_recipe(plotattributes, v::AbstractArray)
isempty(v) && return Float64[]
args = RecipesBase.apply_recipe(d, typeof(v[1]), v[1])[1].args
args = RecipesBase.apply_recipe(plotattributes, typeof(v[1]), v[1])[1].args
if length(args) == 2 && typeof(args[1]) <: Function && typeof(args[2]) <: Function
numfunc, formatter = args
Formatted(map(numfunc, v), formatter)
@@ -197,13 +204,13 @@ function _apply_type_recipe(d, v::AbstractArray)
end
# # special handling for Surface... need to properly unwrap and re-wrap
# function _apply_type_recipe(d, v::Surface)
# function _apply_type_recipe(plotattributes, v::Surface)
# T = eltype(v.surf)
# @show T
# if T <: Integer || T <: AbstractFloat
# v
# else
# ret = _apply_type_recipe(d, v.surf)
# ret = _apply_type_recipe(plotattributes, v.surf)
# if typeof(ret) <: Formatted
# Formatted(Surface(ret.data), ret.formatter)
# else
@@ -213,7 +220,7 @@ end
# end
# don't do anything for ints or floats
_apply_type_recipe(d, v::AbstractArray{T}) where {T<:Union{Integer,AbstractFloat}} = v
_apply_type_recipe(plotattributes, v::AbstractArray{T}) where {T<:Union{Integer,AbstractFloat}} = v
# handle "type recipes" by converting inputs, and then either re-calling or slicing
@recipe function f(x, y, z)
@@ -274,11 +281,11 @@ end
# # --------------------------------------------------------------------
# helper function to ensure relevant attributes are wrapped by Surface
function wrap_surfaces(d::KW)
if haskey(d, :fill_z)
v = d[:fill_z]
function wrap_surfaces(plotattributes::KW)
if haskey(plotattributes, :fill_z)
v = plotattributes[:fill_z]
if !isa(v, Surface)
d[:fill_z] = Surface(v)
plotattributes[:fill_z] = Surface(v)
end
end
end
@@ -428,17 +435,17 @@ end
# # 3d line or scatter
@recipe function f(x::AVec, y::AVec, z::AVec)
# st = get(d, :seriestype, :none)
# st = get(plotattributes, :seriestype, :none)
# if st == :scatter
# d[:seriestype] = :scatter3d
# plotattributes[:seriestype] = :scatter3d
# elseif !is3d(st)
# d[:seriestype] = :path3d
# plotattributes[:seriestype] = :path3d
# end
SliceIt, x, y, z
end
@recipe function f(x::AMat, y::AMat, z::AMat)
# st = get(d, :seriestype, :none)
# st = get(plotattributes, :seriestype, :none)
# if size(x) == size(y) == size(z)
# if !is3d(st)
# seriestype := :path3d
@@ -573,7 +580,7 @@ end
# # create a new series, with the label of the group, and an idxfilter (to be applied in slice_and_dice)
# # TODO: use @series instead
# @show i, glab, groupby.groupIds[i]
# di = copy(d)
# di = copy(plotattributes)
# get!(di, :label, string(glab))
# get!(di, :idxfilter, groupby.groupIds[i])
# push!(series_list, RecipeData(di, args))
@@ -594,12 +601,12 @@ function split_kw(key, val::SeriesAnnotations, indices)
end
function groupedvec2mat(x_ind, x, y::AbstractArray, groupby, def_val = y[1])
y_mat = Array{promote_type(eltype(y), typeof(def_val))}(length(keys(x_ind)), length(groupby.groupLabels))
y_mat = Array{promote_type(eltype(y), typeof(def_val))}(undef, length(keys(x_ind)), length(groupby.groupLabels))
fill!(y_mat, def_val)
for i in 1:length(groupby.groupLabels)
xi = x[groupby.groupIds[i]]
yi = y[groupby.groupIds[i]]
y_mat[getindex.(x_ind, xi), i] = yi
y_mat[getindex.(Ref(x_ind), xi), i] = yi
end
return y_mat
end
@@ -636,7 +643,7 @@ group_as_matrix(t) = false
x = g.args[1]
last_args = g.args[2:end]
end
x_u = unique(x)
x_u = unique(sort(x))
x_ind = Dict(zip(x_u, 1:length(x_u)))
for (key,val) in plotattributes
if splittable_kw(key, val, lengthGroup)
+4 -4
View File
@@ -34,16 +34,16 @@ bottompad(sp::Subplot) = sp.minpad[4]
get_subplot(plt::Plot, sp::Subplot) = sp
get_subplot(plt::Plot, i::Integer) = plt.subplots[i]
get_subplot(plt::Plot, k) = plt.spmap[k]
get_subplot(series::Series) = series.d[:subplot]
get_subplot(series::Series) = series.plotattributes[:subplot]
get_subplot_index(plt::Plot, idx::Integer) = Int(idx)
get_subplot_index(plt::Plot, sp::Subplot) = findfirst(x -> x === sp, plt.subplots)
series_list(sp::Subplot) = sp.series_list # filter(series -> series.d[:subplot] === sp, sp.plt.series_list)
series_list(sp::Subplot) = sp.series_list # filter(series -> series.plotattributes[:subplot] === sp, sp.plt.series_list)
function should_add_to_legend(series::Series)
series.d[:primary] && series.d[:label] != "" &&
!(series.d[:seriestype] in (
series.plotattributes[:primary] && series.plotattributes[:label] != "" &&
!(series.plotattributes[:seriestype] in (
:hexbin,:bins2d,:histogram2d,:hline,:vline,
:contour,:contourf,:contour3d,:surface,:wireframe,
:heatmap, :pie, :image
+4 -4
View File
@@ -21,11 +21,11 @@ Base.isempty(wrapper::InputWrapper) = false
# -----------------------------------------------------------
mutable struct Series
d::KW
plotattributes::KW
end
attr(series::Series, k::Symbol) = series.d[k]
attr!(series::Series, v, k::Symbol) = (series.d[k] = v)
attr(series::Series, k::Symbol) = series.plotattributes[k]
attr!(series::Series, v, k::Symbol) = (series.plotattributes[k] = v)
# -----------------------------------------------------------
@@ -48,7 +48,7 @@ Base.show(io::IO, sp::Subplot) = print(io, "Subplot{$(sp[:subplot_index])}")
# simple wrapper around a KW so we can hold all attributes pertaining to the axis in one place
mutable struct Axis
sps::Vector{Subplot}
d::KW
plotattributes::KW
end
mutable struct Extrema
+94 -106
View File
@@ -19,15 +19,15 @@ A hacky replacement for a histogram when the backend doesn't support histograms
Convert it into a bar chart with the appropriate x/y values.
"""
function histogramHack(; kw...)
d = KW(kw)
plotattributes = KW(kw)
# we assume that the y kwarg is set with the data to be binned, and nbins is also defined
edges, midpoints, buckets, counts = binData(d[:y], d[:bins])
d[:x] = midpoints
d[:y] = float(counts)
d[:seriestype] = :bar
d[:fillrange] = d[:fillrange] == nothing ? 0.0 : d[:fillrange]
d
edges, midpoints, buckets, counts = binData(plotattributes[:y], plotattributes[:bins])
plotattributes[:x] = midpoints
plotattributes[:y] = float(counts)
plotattributes[:seriestype] = :bar
plotattributes[:fillrange] = plotattributes[:fillrange] == nothing ? 0.0 : plotattributes[:fillrange]
plotattributes
end
"""
@@ -35,10 +35,10 @@ A hacky replacement for a bar graph when the backend doesn't support bars direct
Convert it into a line chart with fillrange set.
"""
function barHack(; kw...)
d = KW(kw)
midpoints = d[:x]
heights = d[:y]
fillrange = d[:fillrange] == nothing ? 0.0 : d[:fillrange]
plotattributes = KW(kw)
midpoints = plotattributes[:x]
heights = plotattributes[:y]
fillrange = plotattributes[:fillrange] == nothing ? 0.0 : plotattributes[:fillrange]
# estimate the edges
dists = diff(midpoints) * 0.5
@@ -62,11 +62,11 @@ function barHack(; kw...)
append!(y, [fillrange, heights[i], heights[i], fillrange])
end
d[:x] = x
d[:y] = y
d[:seriestype] = :path
d[:fillrange] = fillrange
d
plotattributes[:x] = x
plotattributes[:y] = y
plotattributes[:seriestype] = :path
plotattributes[:fillrange] = fillrange
plotattributes
end
@@ -75,33 +75,33 @@ A hacky replacement for a sticks graph when the backend doesn't support sticks d
Convert it into a line chart that traces the sticks, and a scatter that sets markers at the points.
"""
function sticksHack(; kw...)
dLine = KW(kw)
dScatter = copy(dLine)
plotattributesLine = KW(kw)
plotattributesScatter = copy(plotattributesLine)
# these are the line vertices
x = Float64[]
y = Float64[]
fillrange = dLine[:fillrange] == nothing ? 0.0 : dLine[:fillrange]
fillrange = plotattributesLine[:fillrange] == nothing ? 0.0 : plotattributesLine[:fillrange]
# calculate the vertices
yScatter = dScatter[:y]
for (i,xi) in enumerate(dScatter[:x])
yScatter = plotattributesScatter[:y]
for (i,xi) in enumerate(plotattributesScatter[:x])
yi = yScatter[i]
for j in 1:3 push!(x, xi) end
append!(y, [fillrange, yScatter[i], fillrange])
end
# change the line args
dLine[:x] = x
dLine[:y] = y
dLine[:seriestype] = :path
dLine[:markershape] = :none
dLine[:fillrange] = nothing
plotattributesLine[:x] = x
plotattributesLine[:y] = y
plotattributesLine[:seriestype] = :path
plotattributesLine[:markershape] = :none
plotattributesLine[:fillrange] = nothing
# change the scatter args
dScatter[:seriestype] = :none
plotattributesScatter[:seriestype] = :none
dLine, dScatter
plotattributesLine, plotattributesScatter
end
function regressionXY(x, y)
@@ -130,10 +130,10 @@ function replace_image_with_heatmap(z::Array{T}) where T<:Colorant
# newz, ColorGradient(colors)
end
function imageHack(d::KW)
function imageHack(plotattributes::KW)
is_seriestype_supported(:heatmap) || error("Neither :image or :heatmap are supported!")
d[:seriestype] = :heatmap
d[:z], d[:fillcolor] = replace_image_with_heatmap(d[:z].surf)
plotattributes[:seriestype] = :heatmap
plotattributes[:z], plotattributes[:fillcolor] = replace_image_with_heatmap(plotattributes[:z].surf)
end
# ---------------------------------------------------------------
@@ -328,16 +328,16 @@ function replaceType(vec, val)
push!(vec, val)
end
function replaceAlias!(d::KW, k::Symbol, aliases::Dict{Symbol,Symbol})
function replaceAlias!(plotattributes::KW, k::Symbol, aliases::Dict{Symbol,Symbol})
if haskey(aliases, k)
d[aliases[k]] = pop!(d, k)
plotattributes[aliases[k]] = pop!(plotattributes, k)
end
end
function replaceAliases!(d::KW, aliases::Dict{Symbol,Symbol})
ks = collect(keys(d))
function replaceAliases!(plotattributes::KW, aliases::Dict{Symbol,Symbol})
ks = collect(keys(plotattributes))
for k in ks
replaceAlias!(d, k, aliases)
replaceAlias!(plotattributes, k, aliases)
end
end
@@ -347,7 +347,7 @@ Base.first(c::Colorant) = c
Base.first(x::Symbol) = x
sortedkeys(d::Dict) = sort(collect(keys(d)))
sortedkeys(plotattributes::Dict) = sort(collect(keys(plotattributes)))
const _scale_base = Dict{Symbol, Real}(
@@ -432,8 +432,8 @@ isscalar(::Any) = false
is_2tuple(v) = typeof(v) <: Tuple && length(v) == 2
isvertical(d::KW) = get(d, :orientation, :vertical) in (:vertical, :v, :vert)
isvertical(series::Series) = isvertical(series.d)
isvertical(plotattributes::KW) = get(plotattributes, :orientation, :vertical) in (:vertical, :v, :vert)
isvertical(series::Series) = isvertical(series.plotattributes)
ticksType(ticks::AVec{T}) where {T<:Real} = :ticks
@@ -492,8 +492,8 @@ end
# this is a helper function to determine whether we need to transpose a surface matrix.
# it depends on whether the backend matches rows to x (transpose_on_match == true) or vice versa
# for example: PyPlot sends rows to y, so transpose_on_match should be true
function transpose_z(d, z, transpose_on_match::Bool = true)
if d[:match_dimensions] == transpose_on_match
function transpose_z(plotattributes, z, transpose_on_match::Bool = true)
if plotattributes[:match_dimensions] == transpose_on_match
# z'
permutedims(z, [2,1])
else
@@ -617,20 +617,40 @@ function hascolorbar(sp::Subplot)
hascbar
end
function get_linecolor(series, i::Int = 1)
lc = series[:linecolor]
lz = series[:line_z]
if lz == nothing
isa(lc, ColorGradient) ? lc : plot_color(_cycle(lc, i))
else
cmin, cmax = get_clims(series[:subplot])
grad = isa(lc, ColorGradient) ? lc : cgrad()
grad[clamp((_cycle(lz, i) - cmin) / (cmax - cmin), 0, 1)]
end
end
for comp in (:line, :fill, :marker)
function get_linealpha(series, i::Int = 1)
_cycle(series[:linealpha], i)
compcolor = string(comp, :color)
get_compcolor = Symbol(:get_, compcolor)
comp_z = string(comp, :_z)
compalpha = string(comp, :alpha)
get_compalpha = Symbol(:get_, compalpha)
@eval begin
function $get_compcolor(series, cmin::Real, cmax::Real, i::Int = 1)
c = series[$Symbol($compcolor)]
z = series[$Symbol($comp_z)]
if z == nothing
isa(c, ColorGradient) ? c : plot_color(_cycle(c, i))
else
grad = isa(c, ColorGradient) ? c : cgrad()
grad[clamp((_cycle(z, i) - cmin) / (cmax - cmin), 0, 1)]
end
end
$get_compcolor(series, clims, i::Int = 1) = $get_compcolor(series, clims[1], clims[2], i)
function $get_compcolor(series, i::Int = 1)
if series[$Symbol($comp_z)] == nothing
$get_compcolor(series, 0, 1, i)
else
$get_compcolor(series, get_clims(series[:subplot]), i)
end
end
$get_compalpha(series, i::Int = 1) = _cycle(series[$Symbol($compalpha)], i)
end
end
function get_linewidth(series, i::Int = 1)
@@ -641,38 +661,6 @@ function get_linestyle(series, i::Int = 1)
_cycle(series[:linestyle], i)
end
function get_fillcolor(series, i::Int = 1)
fc = series[:fillcolor]
fz = series[:fill_z]
if fz == nothing
isa(fc, ColorGradient) ? fc : plot_color(_cycle(fc, i))
else
cmin, cmax = get_clims(series[:subplot])
grad = isa(fc, ColorGradient) ? fc : cgrad()
grad[clamp((_cycle(fz, i) - cmin) / (cmax - cmin), 0, 1)]
end
end
function get_fillalpha(series, i::Int = 1)
_cycle(series[:fillalpha], i)
end
function get_markercolor(series, i::Int = 1)
mc = series[:markercolor]
mz = series[:marker_z]
if mz == nothing
isa(mc, ColorGradient) ? mc : plot_color(_cycle(mc, i))
else
cmin, cmax = get_clims(series[:subplot])
grad = isa(mc, ColorGradient) ? mc : cgrad()
grad[clamp((_cycle(mz, i) - cmin) / (cmax - cmin), 0, 1)]
end
end
function get_markeralpha(series, i::Int = 1)
_cycle(series[:markeralpha], i)
end
function get_markerstrokecolor(series, i::Int = 1)
msc = series[:markerstrokecolor]
isa(msc, ColorGradient) ? msc : _cycle(msc, i)
@@ -818,20 +806,20 @@ end
debugshow(x) = show(x)
debugshow(x::AbstractArray) = print(summary(x))
function dumpdict(d::KW, prefix = "", alwaysshow = false)
function dumpdict(plotattributes::KW, prefix = "", alwaysshow = false)
_debugMode.on || alwaysshow || return
println()
if prefix != ""
println(prefix, ":")
end
for k in sort(collect(keys(d)))
for k in sort(collect(keys(plotattributes)))
@printf("%14s: ", k)
debugshow(d[k])
debugshow(plotattributes[k])
println()
end
println()
end
DD(d::KW, prefix = "") = dumpdict(d, prefix, true)
DD(plotattributes::KW, prefix = "") = dumpdict(plotattributes, prefix, true)
function dumpcallstack()
@@ -857,25 +845,25 @@ tovec(v::AbstractVector) = v
tovec(v::Nothing) = zeros(0)
function getxy(plt::Plot, i::Integer)
d = plt.series_list[i].d
tovec(d[:x]), tovec(d[:y])
plotattributes = plt.series_list[i].plotattributes
tovec(plotattributes[:x]), tovec(plotattributes[:y])
end
function getxyz(plt::Plot, i::Integer)
d = plt.series_list[i].d
tovec(d[:x]), tovec(d[:y]), tovec(d[:z])
plotattributes = plt.series_list[i].plotattributes
tovec(plotattributes[:x]), tovec(plotattributes[:y]), tovec(plotattributes[:z])
end
function setxy!(plt::Plot, xy::Tuple{X,Y}, i::Integer) where {X,Y}
series = plt.series_list[i]
series.d[:x], series.d[:y] = xy
sp = series.d[:subplot]
series.plotattributes[:x], series.plotattributes[:y] = xy
sp = series.plotattributes[:subplot]
reset_extrema!(sp)
_series_updated(plt, series)
end
function setxyz!(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) where {X,Y,Z}
series = plt.series_list[i]
series.d[:x], series.d[:y], series.d[:z] = xyz
sp = series.d[:subplot]
series.plotattributes[:x], series.plotattributes[:y], series.plotattributes[:z] = xyz
sp = series.plotattributes[:subplot]
reset_extrema!(sp)
_series_updated(plt, series)
end
@@ -924,9 +912,9 @@ Base.push!(series::Series, xi, yi, zi) = (push_x!(series,xi); push_y!(series,yi)
# -------------------------------------------------------
function attr!(series::Series; kw...)
d = KW(kw)
preprocessArgs!(d)
for (k,v) in d
plotattributes = KW(kw)
preprocessArgs!(plotattributes)
for (k,v) in plotattributes
if haskey(_series_defaults, k)
series[k] = v
else
@@ -938,9 +926,9 @@ function attr!(series::Series; kw...)
end
function attr!(sp::Subplot; kw...)
d = KW(kw)
preprocessArgs!(d)
for (k,v) in d
plotattributes = KW(kw)
preprocessArgs!(plotattributes)
for (k,v) in plotattributes
if haskey(_subplot_defaults, k)
sp[k] = v
else
@@ -1069,9 +1057,9 @@ mm2px(mm::Real) = float(px / MM_PER_PX)
"Smallest x in plot"
xmin(plt::Plot) = ignorenan_minimum([ignorenan_minimum(series.d[:x]) for series in plt.series_list])
xmin(plt::Plot) = ignorenan_minimum([ignorenan_minimum(series.plotattributes[:x]) for series in plt.series_list])
"Largest x in plot"
xmax(plt::Plot) = ignorenan_maximum([ignorenan_maximum(series.d[:x]) for series in plt.series_list])
xmax(plt::Plot) = ignorenan_maximum([ignorenan_maximum(series.plotattributes[:x]) for series in plt.series_list])
"Extrema of x-values in plot"
ignorenan_extrema(plt::Plot) = (xmin(plt), xmax(plt))
+1
View File
@@ -2,6 +2,7 @@ StatPlots
Images
ImageMagick
@osx QuartzImageIO
FileIO
GR 0.31.0
RDatasets
VisualRegressionTests
+35
View File
@@ -0,0 +1,35 @@
using Pkg
# need this to use Conda
# ENV["PYTHON"] = ""
to_add = [
PackageSpec(url="https://github.com/JuliaPlots/PlotReferenceImages.jl.git"),
# PackageSpec(url="https://github.com/JuliaStats/KernelDensity.jl.git"),
PackageSpec(name="PlotUtils", rev="master"),
PackageSpec(name="RecipesBase", rev="master"),
# PackageSpec(name="Blink", rev="master"),
# PackageSpec(name="Rsvg", rev="master"),
# PackageSpec(name="PlotlyJS", rev="master"),
# PackageSpec(name="VisualRegressionTests", rev="master"),
# PackageSpec("PyPlot"),
# PackageSpec("InspectDR"),
]
if isinteractive()
append!(to_add, [
PackageSpec(name="FileIO"),
PackageSpec(name="ImageMagick"),
PackageSpec(name="UnicodePlots"),
PackageSpec(name="VisualRegressionTests"),
])
end
Pkg.add(to_add)
Pkg.build("ImageMagick")
# Pkg.build("GR")
# Pkg.build("Blink")
# import Blink
# Blink.AtomShell.install()
# Pkg.build("PyPlot")
+13 -7
View File
@@ -2,6 +2,10 @@
using VisualRegressionTests
# using ExamplePlots
if isinteractive()
@eval Main import Gtk
end
# import DataFrames, RDatasets
# don't let pyplot use a gui... it'll crash
@@ -9,12 +13,14 @@ using VisualRegressionTests
# ENV["MPLBACKEND"] = "Agg"
# try
# @eval import PyPlot
# info("Matplotlib version: $(PyPlot.matplotlib[:__version__])")
# @info("Matplotlib version: $(PyPlot.matplotlib[:__version__])")
# end
using Plots
# using StatPlots
import PlotReferenceImages
using Random
using Test
default(size=(500,300))
@@ -26,10 +32,10 @@ default(size=(500,300))
const _current_plots_version = v"0.17.4"
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], eps = 1e-2)
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], tol = 1e-2)
Plots._debugMode.on = debug
example = Plots._examples[idx]
info("Testing plot: $pkg:$idx:$(example.header)")
@info("Testing plot: $pkg:$idx:$(example.header)")
backend(pkg)
backend()
@@ -38,7 +44,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is
# reference image directory setup
# refdir = joinpath(Pkg.dir("ExamplePlots"), "test", "refimg", string(pkg))
refdir = Pkg.dir("PlotReferenceImages", "Plots", string(pkg))
refdir = joinpath(dirname(pathof(PlotReferenceImages)), "..", "Plots", string(pkg))
fn = "ref$idx.png"
# firgure out version info
@@ -83,7 +89,7 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is
# the test
vtest = VisualTest(func, reffn, idx)
test_images(vtest, popup=popup, sigma=sigma, eps=eps, newfn = newfn)
test_images(vtest, popup=popup, sigma=sigma, tol=tol, newfn = newfn)
end
function image_comparison_facts(pkg::Symbol;
@@ -91,11 +97,11 @@ function image_comparison_facts(pkg::Symbol;
only = nothing, # limit to these examples (int index)
debug = false, # print debug information?
sigma = [1,1], # number of pixels to "blur"
eps = 1e-2) # acceptable error (percent)
tol = 1e-2) # acceptable error (percent)
for i in 1:length(Plots._examples)
i in skip && continue
if only == nothing || i in only
@test image_comparison_tests(pkg, i, debug=debug, sigma=sigma, eps=eps) |> success == true
@test image_comparison_tests(pkg, i, debug=debug, sigma=sigma, tol=tol) |> success == true
end
end
end
+10 -9
View File
@@ -1,11 +1,12 @@
module PlotsTests
include("add_packages.jl")
include("imgcomp.jl")
# don't actually show the plots
Random.seed!(1234)
default(show=false, reuse=true)
img_eps = isinteractive() ? 1e-2 : 10e-2
img_tol = isinteractive() ? 1e-2 : 10e-2
@testset "GR" begin
ENV["PLOTS_TEST"] = "true"
@@ -13,7 +14,7 @@ img_eps = isinteractive() ? 1e-2 : 10e-2
@test gr() == Plots.GRBackend()
@test backend() == Plots.GRBackend()
image_comparison_facts(:gr, eps=img_eps, skip = [25, 30])
image_comparison_facts(:gr, tol=img_tol, skip = [25, 30])
end
@@ -21,7 +22,7 @@ end
# @test pyplot() == Plots.PyPlotBackend()
# @test backend() == Plots.PyPlotBackend()
#
# image_comparison_facts(:pyplot, eps=img_eps)
# image_comparison_facts(:pyplot, tol=img_tol)
#end
@testset "UnicodePlots" begin
@@ -46,7 +47,7 @@ end
# 27, # (polar plots) takes very long / not working
# 31, # animation (skipped for speed)
# ],
# eps=img_eps)
# tol=img_tol)
# end
# end
@@ -70,7 +71,7 @@ end
# 28, # heatmap not defined
# 31, # animation
# ],
# eps=img_eps)
# tol=img_tol)
# end
@@ -79,7 +80,7 @@ end
# @test backend() == Plots.PlotlyBackend()
#
# # # until png generation is reliable on OSX, just test on linux
# # @static Sys.islinux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps)
# # @static Sys.islinux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], tol=img_tol)
# end
@@ -88,7 +89,7 @@ end
# @test backend() == Plots.ImmerseBackend()
#
# # as long as we can plot anything without error, it should be the same as Gadfly
# image_comparison_facts(:immerse, only=[1], eps=img_eps)
# image_comparison_facts(:immerse, only=[1], tol=img_tol)
# end
@@ -97,7 +98,7 @@ end
# @test backend() == Plots.PlotlyJSBackend()
#
# # as long as we can plot anything without error, it should be the same as Plotly
# image_comparison_facts(:plotlyjs, only=[1], eps=img_eps)
# image_comparison_facts(:plotlyjs, only=[1], tol=img_tol)
# end
@@ -110,7 +111,7 @@ end
# @test plot(sort(rand(10)), rand(Int, 10, 3)) == not(nothing)
# @test plot!(rand(10,3), rand(10,3)) == not(nothing)
#
# image_comparison_facts(:gadfly, skip=[4,6,23,24,27], eps=img_eps)
# image_comparison_facts(:gadfly, skip=[4,6,23,24,27], tol=img_tol)
# end
-34
View File
@@ -1,34 +0,0 @@
using Pkg
Pkg.add("ImageMagick")
Pkg.build("ImageMagick")
# Pkg.clone("GR")
# Pkg.build("GR")
Pkg.checkout("https://github.com/JuliaPlots/PlotReferenceImages.jl.git")
# Pkg.clone("https://github.com/JuliaStats/KernelDensity.jl.git")
# Pkg.add("StatPlots")
Pkg.checkout("PlotUtils")
Pkg.checkout("RecipesBase")
# Pkg.clone("Blink")
# Pkg.build("Blink")
# import Blink
# Blink.AtomShell.install()
# Pkg.add("Rsvg")
# Pkg.add("PlotlyJS")
# Pkg.checkout("RecipesBase")
# Pkg.clone("VisualRegressionTests")
# need this to use Conda
# ENV["PYTHON"] = ""
# Pkg.add("PyPlot")
# Pkg.build("PyPlot")
# Pkg.add("InspectDR")
Pkg.test("Plots"; coverage=false)