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

Feature request: default names to axis #41

Closed
piever opened this issue Jan 5, 2018 · 3 comments
Closed

Feature request: default names to axis #41

piever opened this issue Jan 5, 2018 · 3 comments

Comments

@piever
Copy link
Contributor

piever commented Jan 5, 2018

There are case where, from the function call, the plotting package can determine how to label the axis and the legend:

  • when using the @df macro in StatPlots to plot columns a data table: the axis should be labelled with the appropriate column label

  • when using some macro mechanism, for example @label plot(X, [Z, logistic.(Z)]) (see #1072 ) could create a legend with entries Z and logistic.(Z)

The difficulty with implementing this is that the translation from the argument names (as visible at "macroexpand" time) to the axis of the plot is not straightforward (for example plot(y) should have a y axis label and density(y) should have a x axis label) which makes these macros tricky to write.

The best solution we could find was to add a _default_names keyword argument to all plot calls, which would take all the extra label info from the macro (basically all the names of the main arguments, which could correspond to x,y, z or to the legend if the user is passing a vector of vectors such as [Z, logistic.(Z)]), combine it with the label explicitly provided by the user (which should have priority) and label the plot appropriately. Then writing these macros becomes very simple.

It could be a bit painful to add this _default_names keyword a posteriori so I thought I should mention it already.

See here for previous discussion.

@SimonDanisch
Copy link
Member

I plan to have themes for recipes, so e.g. density would have it's own theme node, which can be used to store information like label names. Would that solve one part of this?

For the macro, I would implement it as:

>macroexpand(@label plot(X, [Z, logistic.(Z)]); kw_args...) # with kw_args e.g. ylabel = "Owerwrite Z"
plot(X, [Z, logistic.(Z)], Scene(xlabel = "Z", ylabel = "logistic.(Z)"); kw_args...)

The plot will inherit attributes from Scene, but they will still be overwriteable by the user (as pointed out in #10)!

Is this solving the issue completely, or would you argue that having _default_names still needs to exist?

@piever
Copy link
Contributor Author

piever commented Jan 5, 2018

I think the Scene idea solves the "overridable default" part, but there are two issues to keep in mind:

  1. Figuring out which arguments are x or y (the main issue being that in plot plot(x) is the same as plot(1:length(x), x) so the x ends up on the y axis). If that method is not allowed in Makie, this should be solved

  2. In this example case, I would actually want:

@macroexpand @label plot(X, [Z, logistic.(Z)]); kw_args...) 
plot(X, [Z, logistic.(Z)], xlabel = "Z", label = ["Z" "logistic.(Z)"]; kw_args...)

because the ylabel is a vector and is better expressed as a legend:

@plot (X, [Z, logistic.(Z)])

If issue one is not a problem (that is to say, you don't need to know the plot type to know what goes on what axis), then it'd be sufficient to have a function create_label_scene(labels) that creates the Scene with the defaults, checking out whether the labels are symbols or vectors and deciding how to use them accordingly.

Anyway, I'll try to start porting the @df macro as soon as I have a bit more time and I'll see where/how I get stuck. Is the recipe system still in flux or it is already safe to port things?

@SimonDanisch
Copy link
Member

It's not really there yet! Still fighting with my refactor of scene creation, layouting and units...
I'll make a release with some demos once it's out!

Anyways, I think I first didn't understand your problem & solution correctly ;) I will think about this - if _default_names is the best solution, I don't see why we shouldn't add it!

It could be a bit painful to add this _default_names keyword a posteriori so I thought I should mention it already.

This should be no problem. There is a single location in Makie, were one can add kw_args to every plotting function.

SimonDanisch pushed a commit that referenced this issue Jun 3, 2021
SimonDanisch added a commit that referenced this issue Jun 3, 2021
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

No branches or pull requests

2 participants