Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Plot and axis-like types. #67

Merged
merged 3 commits into from
Feb 21, 2018
Merged

Rewrite Plot and axis-like types. #67

merged 3 commits into from
Feb 21, 2018

Conversation

tpapp
Copy link
Collaborator

@tpapp tpapp commented Feb 15, 2018

This is a step towards fixing #44 (almost there!).

  1. New user-facing plot/plot3 constructor is
Plot([incrementa], [options], data, trailing...)

and similarly for Plot3.

incremental defaults to false, as this seems to be the most common use case.

Some validation is done on data (checking for type).

This removes the label kwarg, and allows us to close #16. Examples now recommend an explicit \addlegendentry.

Docstrings are added for everything, and examples are rewritten accordingly.

  1. Axis-like code cleaned up a bit with macros. Variations on log axes added. Explicitly document that strings are emitted as is.

  2. GroupPlot rewritten, allow multiple plots and empty \nextgroupplot, two examples added, one from the manual and one for multiple plots.

  3. Replaced random examples with deterministic ones, perhaps stick to this and close Use a seed for figures using random data. #63? Minor indentation issues fixed.

  4. Minor fixes for testing framework.

This is a step towards fixing #44 (almost there!).

1. New user-facing plot/plot3 constructor is

```julia
Plot([incrementa], [options], data, trailing...)
```
and similarly for `Plot3`.

`incremental` defaults to `false`, as this seems to be the most common
use case.

Some validation is done on `data` (checking for type).

This removes the `label` kwarg, and allows us to close #16. Examples
now recommend an explicit `\addlegendentry`.

Docstrings are added for everything, and examples are rewritten
accordingly.

2. Axis-like code cleaned up a bit with macros. Variations on log axes
added. Explicitly document that strings are emitted as is.

3. GroupPlot rewritten, allow multiple plots and empty \nextgroupplot,
two examples added, one from the manual and one for multiple plots.

4. Replaced random examples with deterministic ones, perhaps stick to
this and close #63? Minor indentation issues fixed.

5. Minor fixes for testing framework.
@codecov-io
Copy link

codecov-io commented Feb 15, 2018

Codecov Report

Merging #67 into master will increase coverage by 3.53%.
The diff coverage is 91.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #67      +/-   ##
==========================================
+ Coverage   77.75%   81.28%   +3.53%     
==========================================
  Files           9        9              
  Lines         472      481       +9     
==========================================
+ Hits          367      391      +24     
+ Misses        105       90      -15
Impacted Files Coverage Δ
src/PGFPlotsX.jl 94.11% <ø> (+11.76%) ⬆️
src/axiselements.jl 94.51% <90.9%> (+3.12%) ⬆️
src/axislike.jl 92.85% <92.3%> (+14.73%) ⬆️
src/options.jl 86.95% <0%> (+8.69%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd09bcb...e52ae2a. Read the comment docs.


Corresponds to the `\\addplot[3][+]` family of `pgfplot` commands.

The 1-4+ argument outer constructors `Plot` and `Plot3` should be used in user
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand this sentence.

Base.append!(plot::Plot, element) = (append!(plot.trailing, element); plot)

"""
Plot([incremental::Bool], [options::Options], data, trailing...)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for not having incremental as a keyword is that we want it early, together with the options? Makes some sense but Plot(true, ...) will look kinda nondescriptive (and ugly), what is true there?

Perhaps we should just have a convenience constructor for this instead, in the same way we have for Plot3? Ploti, PlotInc or something?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also a little bit sad to see the keyword argument to give a legend to a plot go away. This is just such a common operation to do and having to do raw"\addlegendentry... doesn't feel nice. Would deprecating the label keyword into a legend or something be that bad?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, the boolean is kind of awkward, and I think that Plot[3]Inc is the best way to go forward, I will do that.

Regarding \addlegendentry: I realized that it is more complex than I thought, it can even take options etc, so adding a form for that, too.

I am against the keyword in Plot & friends, as that would break the very clear mapping between this package and pgfplots constructs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am against the keyword in Plot & friends, as that would break the very clear mapping between this package and pgfplots constructs.

Ok, I can respect that.

function (T::Type{<:AxisLike})(args::Vararg{PGFOption})
T([], args...)
end
Return the corresponding LaTeX environment name.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need to be mentioned in the docs? It feels like this is an internal thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a difference in our coding style; I like to document internal functions too, and indicate what belongs to the API with export and documentation. I can make it a comment if you prefer.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, just leave it like this then.


Same as [`Plot(::Bool, ::Options, ::PlotData, ...)`](@ref), but for 3D plots.
"""
Plot3(incremental::Bool, options::Options, data::PlotData, trailing...) =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't

Plot3(args...; kwargs...) = Plot(true, args...; kwargs...)

enough to cover everything here?

const INCREMENTAL = false

"Types accepted by `Plot` for the field `data`."
const PlotData = Union{Coordinates, Table, TableFile, Expression, Graphics}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there ever a case where you would want to add a String to a Plot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I know of. Expression pretty much covers those.

The `incremental` flag was removed from `Plot*` constructors in the
API, replaced by `PlotInc` and `Plot3Inc`.

A LegendEntry type was added.

Minor fixes:

- remove the INCREMENTAL constant, as it is now unnecessary

- clarify docstrings

- disabled docstring checks, as they lead to infinite loops for some
  reason
@tpapp
Copy link
Collaborator Author

tpapp commented Feb 21, 2018

@KristofferC: I think I fixed everything, OK if I merge?

@KristofferC
Copy link
Owner

Alright, we'll have to decide later wether to worry about deprecating old functionality. Running through all the examples in the PGFPlotsXExamples.jl and see what has broken could be a way to do that.

@KristofferC KristofferC merged commit 362f58d into master Feb 21, 2018
@tpapp tpapp deleted the tp/plot-rewrite branch February 21, 2018 13:01
tpapp added a commit that referenced this pull request Feb 23, 2018
Introduced a mixture of incremental and non-incremental forms, to demo both.
KristofferC pushed a commit that referenced this pull request Feb 23, 2018
Introduced a mixture of incremental and non-incremental forms, to demo both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use a seed for figures using random data. Introduce new kwarg "legend"
3 participants