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

add Plots.jl recipes #94

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BeastyBlacksmith
Copy link

This adds two recipes to automatically set the labels.

using TypedTables, Plots
tt = Table(a=[1,2,3], b=[4,3,6], c=[0.2,2.0,5.4])
plot(tt)

gives takes first column as x and second column as y.
Then you can use either of

plot(tt; indices = [2,3])
plot(tt, (:a, :c))

to get other combinations.

Currently this only works for Tables, but with a common supertype this could potentially be extended to more TypedTables.

@andyferris
Copy link
Member

Out of curiosity… should this be done for the Tables.jl interface in general?

@BeastyBlacksmith
Copy link
Author

Might be useful, if that is feasible, but I don't know the interface very well to judge that

Indexing = "1"
SplitApplyCombine = "1"
Tables = "1"
Dictionaries = "0.3"
julia = "1"
Copy link
Member

Choose a reason for hiding this comment

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

Will need to add a compat entry here for RecipesBase or the General registry will reject a new release

@recipe function f(tt::Table; indices = [1,2])
if length(indices) == 2
x_name, y_name = propertynames(tt)[indices]
xguide --> string(x_name)
Copy link
Member

Choose a reason for hiding this comment

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

What does the --> operator do here?

Copy link
Author

Choose a reason for hiding this comment

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

it's "use this value if the user didn't provide a different value"

@@ -0,0 +1,33 @@
@recipe function f(tt::Table; indices = [1,2])
if length(indices) == 2
x_name, y_name = propertynames(tt)[indices]
Copy link
Member

Choose a reason for hiding this comment

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

For generic Tables.jl, this would be: x_name, y_name = Tables.columnnames(tt)[indices]

x_name, y_name = propertynames(tt)[indices]
xguide --> string(x_name)
yguide --> string(y_name)
return getproperty(tt, x_name), getproperty(tt, y_name)
Copy link
Member

Choose a reason for hiding this comment

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

For generic Tables.jl, these would be Tables.getcolumn(tt, x_name), Tables.getcolumn(tt, y_name)

@quinnj
Copy link
Member

quinnj commented Jun 22, 2022

Seems to me like it could work on generic Tables.jl given what is defined here; I don't know RecipesBase.jl well enough to know what kind of dependency it is, but we could look into adding this to Tables.jl directly.

@andyferris
Copy link
Member

I don't know RecipesBase.jl well enough to know what kind of dependency it is

It seems to be a single ~500-line file. Like Tables.jl it's mostly there to provide the interface to be imported and extended, so I suspect there's some synergy. Does DataFrames already have the equivalent of this PR?

@BeastyBlacksmith
Copy link
Author

Does DataFrames already have the equivalent of this PR?

I didn't make any other PRs. StatsPlots.jl has a @df macro that can be used to extract columns at the call site, that is scheduled to be moved to Plots.jl for 2.0 (no timeframe though).

I'll also note that DimensionalData.jl provides a set of more elaborate recipes, but I tried to keep things minimalistic here.

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.

3 participants