Skip to content

Added silhouette plot#269

Open
tobydriscoll wants to merge 8 commits intoJuliaPlots:masterfrom
tobydriscoll:silhouette
Open

Added silhouette plot#269
tobydriscoll wants to merge 8 commits intoJuliaPlots:masterfrom
tobydriscoll:silhouette

Conversation

@tobydriscoll
Copy link
Copy Markdown

This goes to address issue JuliaPlots/Plots.jl#5495.

Copy link
Copy Markdown
Member

@mkborregaard mkborregaard left a comment

Choose a reason for hiding this comment

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

Thanks, this looks nice. I've a few questions.

Comment thread src/silhouetteplot.jl Outdated

# Settings for the axes
legend --> false
yflip := true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do you override settings for these three attributes? Might --> not be better?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yflip needs to be known in order to get the sorting order right. I'm not sure how to read that attribute if it wasn't set explicitly, and I thought top-to-bottom was most natural.

xlims and yticks should probably be "soft" assignments, I agree. Will modify.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Actually, I've learned that if I don't assign yticks:=, the labels don't get preserved. I'd really rather show the size of each cluster than the cumulative sizes. Do you know a fix?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can get the value by plotattributes[:yticks], I think. You can also read it, and then explicitly assign what you read to it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No, if I try to reference plotattributes[:yticks] when it was left unset in the invoking plot command, I get a "key not found" error. I suppose that unset attributes aren't given values until later in the pipeline.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've just avoided the issue by making yflip a keyword setting in silhouetteplot. It's true by default, but setting it to false is respected.

Comment thread src/silhouetteplot.jl Outdated
plt = plot([],label="")
for i in 1:k
idx = (a.==i) # members of cluster i
si = sort(s[idx],rev=true)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

better to use filter here which avoids allocating the temporary idx array

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry, I don't know how that works when the filtered array is not the one on which the selection is predicated. It's a boolean vector, so it's probably not creating a big performance issue.

Comment thread src/silhouetteplot.jl
si = sort(s[idx],rev=true)
@series begin
linealpha --> 0
seriestype := :shape
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do you use shape? I think just a line with a fillto argument might be simpler (try to run plot(sort(randn(1000)), fillto = 0) to see the effect) and easier?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Does fillto work horizontally?

Comment thread src/silhouetteplot.jl Outdated
Comment thread src/silhouetteplot.jl Outdated
tobydriscoll added a commit to tobydriscoll/StatsPlots.jl that referenced this pull request Nov 19, 2019
Comment thread Project.toml Outdated
@tobydriscoll
Copy link
Copy Markdown
Author

Can I get an update on the changes requested to this PR?

@mkborregaard
Copy link
Copy Markdown
Member

@tobydriscoll really sorry for the ridiculously late response here. Could you rebase this onto master resolving the conflicts, and add an example to the Readme documenting the use of this function? Then I'll merge. Thanks, and sorry again.

@tobydriscoll
Copy link
Copy Markdown
Author

Updated the example in documentation string and the README.

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