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 white templates with axes lines, tickmarks, and different color rotation #1834

Closed
joelostblom opened this issue Oct 19, 2019 · 9 comments · Fixed by #1864
Closed

Add white templates with axes lines, tickmarks, and different color rotation #1834

joelostblom opened this issue Oct 19, 2019 · 9 comments · Fixed by #1864

Comments

@joelostblom
Copy link
Contributor

joelostblom commented Oct 19, 2019

Would you consider adding two templates with axis lines, tickmarks, and white background (similar to "xticks" in seaborn)? I believe this is a rather common style in various plotting libraries that also looks good in print and it would be nice to have it easily accessible, especially when teaching so that custom templates need not to be explained early on.

To illustrate what I mean

image

And with gridlines

image

I also changed the color rotations to D3, viridis, and RdBu, which are common defaults elsewhere. Below is the code I used to create the first figure, it is not complete with the figure specific template properties that are in the other default templates but gives an idea of what I am referring to.

go.layout.Template(
    layout=go.Layout(
        hovermode='closest',
        hoverlabel_align='left',
        plot_bgcolor='white',
        paper_bgcolor='white',
        font_size=13,
        xaxis=dict(showline=True, ticks='outside', showgrid=False,
                   linewidth=1.5, zeroline=False),
        yaxis=dict(showline=True, ticks='outside', showgrid=False,
                   linewidth=1.5, zeroline=False),
        colorway=px.colors.qualitative.D3,
        colorscale=dict(sequential=px.colors.sequential.Viridis,
                        diverging=px.colors.diverging.RdBu), 
    )
)
@nicolaskruchten
Copy link
Contributor

This makes sense, and it's also quite close to the previous default/"none" built-in template... We could maybe break this apart into some "aspect"-like templates that could be layered? Like a "nogrid" and "outsideticks" and then you could get what you're looking for with "none+nogrid+outsideticks" or something?

@joelostblom
Copy link
Contributor Author

I like the flexibility in combining granular templates like that, and it makes it easier to remember templates if the name indicates what they do. I would be a little worried about about clarity and verbosity when around 4-5 templates are combined, e.g. 'none+axislines+nogrid+nozero+outsideticks+vibrantcolors'. Maybe it would be worth adding one with that (or a similar) combination in addition to the granular ones?

@nicolaskruchten
Copy link
Contributor

I'm pretty open to adding new templates, I mostly want them to be "more different" from the existing defaults... How different are what are you proposing from the existing "none" template? I can mostly see the outside ticks and the yes or no gridlines, but maybe there are other aspects that are important to you?

@nicolaskruchten
Copy link
Contributor

I guess one thing that comes to mind from looking at this is that maybe we need an additional .update* method that targets both x and y axes, to cut down on repetition of this kind?

image

@joelostblom
Copy link
Contributor Author

joelostblom commented Oct 21, 2019

In addition to what you mentioned, I think the color rotations and slightly larger fonts are nice to set once in the default. I also want to experiment with having the background of the hover popup in white for all marker instead of the same color as the marker, but I haven't gotten there yet.

Eventually, I think it would be helpful if the subplot column titles and legend could have the species= part removed via the template instead of by updating the traces manually for each plot (which is what I understood from a separate answer you gave regarding the legend, not sure if it is at all possible for the column titles, but I'm still new to plotly and express so I'm probably missing something).

@nicolaskruchten
Copy link
Contributor

background of the hover popup in white for all marker instead of the same color as the marker, but I haven't gotten there yet.

That's pretty easy, there's an attribute for that in the layout

Eventually, I think it would be helpful if the subplot column titles and legend could have the species= part removed via the template

that's not going to be possible at all via layout.template as it's not something that maps to a single figure attribute, although it seems to be a popular enough request that we may end up just adding an additional kwarg for that to all PX methods, or a PX-level overrideable default or something.

@joelostblom
Copy link
Contributor Author

I just held a short Plotly express tutorial for a dozen people from my lab and it was very well received! People found it intuitive and powerful! Participants were beginners to programmatic data analysis and visualization.

One thing that did come up was that many didn't like the default grey backgrounds (probably because it is uncommon in my field, biomed). When we switched to white backgrounds (the none template), the lack of axes lines (and occasional appearance of zerolines depending on the data range) were unexpected and confusing, especially when working with facets since the subplots float together without any clear separator between them. To illustrate this point, compare this

px.scatter(tips, 'total_bill', 'tip', facet_col='smoker', facet_row='day',
           template=axes_lines, range_x=(1, 40), width=600)

image

with this

px.scatter(tips, 'total_bill', 'tip', facet_col='smoker', facet_row='day',
           template=axes_lines, range_x=(1, 40), width=600)

image

(note that I changed the axes lines to 1 instead of 1.5 from what I suggested initially, I think these thinner lines looks better)

My opinion is that tickmark labels and data points are noticeably more "anchored" in the second plot, whereas in the first they appear to float around more. Based on this and what I wrote previously, I think the addition of a white template (either with or without gridlines), with axes lines, and without zero lines (and changing the color to something that looks good on white, such as D3), would be a welcome addition. Happy to PR a suggestion or discuss further.


that's not going to be possible at all via layout.template as it's not something that maps to a single figure attribute, although it seems to be a popular enough request that we may end up just adding an additional kwarg for that to all PX methods, or a PX-level overrideable default or something.

A px default would be great for these! I would even suggest that the default behavior is to omit the column names (definitely in the color legend and preferably in the subplot title as well). In my experience this is the most commonly desired behavior (but I of course don't have any data to back this up...).

I saw in one of your comments elsewhere that one of the reasons for the current behavior was to handle cases such as when you have a column, say smoker, with Yes/No values. I would be inclined to believe that this is rarer than having a column with labels, and also easy to change to labels (smoker/non-smoker) if desired (or of course with a default px option). What do you think about this?

@nicolaskruchten
Copy link
Contributor

Thanks for the candid feedback! As I said, I'd be open to a PR with a new template :) The screenshots above look a lot like the Seaborn style="ticks" look so we could call it seaborn_ticks unless it sometimes behaves quite differently.

With respect to the PX col=val labelling, this probably belongs in a different issue, as it cannot be addressed in a template, but my feeling is that I like the way Seaborn does it, with col=val on the facet labels but not in the legend. Today plotly.js doesn't support legend titles, but when it does we will likely remove this from the trace names, which will address most people's concerns. See plotly/plotly.js#276 for the legend title issue.

@nicolaskruchten
Copy link
Contributor

Heads-up: 4.3 is coming out this week! Last call for PRs for this release is getting close ;)

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 a pull request may close this issue.

2 participants