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 plotly backend and gallery prototype #61

Merged
merged 16 commits into from
Jul 25, 2024
Merged

Add plotly backend and gallery prototype #61

merged 16 commits into from
Jul 25, 2024

Conversation

OriolAbril
Copy link
Member

@OriolAbril OriolAbril commented Jul 3, 2024


📚 Documentation preview 📚: https://arviz-plots--61.org.readthedocs.build/en/61/

@codecov-commenter
Copy link

codecov-commenter commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 82.56228% with 49 lines in your changes missing coverage. Please review.

Project coverage is 85.14%. Comparing base (1298e42) to head (f90dd65).
Report is 1 commits behind head on main.

Files Patch % Lines
src/arviz_plots/backend/plotly/__init__.py 85.84% 30 Missing ⚠️
src/arviz_plots/style.py 9.09% 10 Missing ⚠️
src/arviz_plots/backend/bokeh/__init__.py 50.00% 7 Missing ⚠️
src/arviz_plots/__init__.py 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
- Coverage   85.85%   85.14%   -0.72%     
==========================================
  Files          17       20       +3     
  Lines        1951     2194     +243     
==========================================
+ Hits         1675     1868     +193     
- Misses        276      326      +50     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@OriolAbril OriolAbril changed the title plotly backend proof of concept Add plotly backend and gallery prototype Jul 6, 2024
@OriolAbril
Copy link
Member Author

I have added a simpler gallery_generator extension. I would like to change how things are documented a bit, having less examples in the docstring (not no examples though, but mostly examples that complement the docstring) and links from the docstrings to all example gallery pages that use it (where all backends will be shown instead of only matplotlib).

Consequently, instead of the python script with a docstring at its top, I think it will be easier to have two files with the same name one python the other markdown. We could go back to single py file with docstring, but I would "simplify" things and have the docstring be valid markdown/myst and added as is to the page for rendering.

@OriolAbril OriolAbril requested a review from aloctavodia July 25, 2024 00:52
@OriolAbril
Copy link
Member Author

Ready to merge! 🎉

I am quite happy with the example gallery. It has a lot of common elements with the original one: cool css thanks to Sarina, tabs for different backends, link to api docs and to download the script. And in addition it has several improvements:

  • Thanks to the refactoring the script is now shared, the only thing that changes is the backend="none" part. The line with that content has a comment to indicate so, and is also highlighted so it gets extra emphasis.
  • Consequently, only the plots themselves are inside the tab, and tab management has gotten much better, both due to new features in sphinx-design extension and due to better use of them on our side. Now tabs should sync across pages. That is, if I select the plotly backend on the plot_forest page and them move to the plot_dist one, the active tab should continue to be the plotly one. Moreover, it is possible to share links that will open the page with a specific tab as the active one using ?backend=plotly#synchronised-tabs suffix for the html (these html are also present in the bokeh and plotly tabs so users are aware of the possibility).
  • Everything continues to be in a single python file with a docstring at the bottom, but processing of the content has changed and is now a bit simpler. First the content of the python file is splitted between code and docstring, then the docstring is splitted in two using --- as separator. When putting the page together, the content above the --- goes at the top, then comes the tabs and code snippet (properly processed automatically to generate all backends and such), then the content below the --- and eventually the download button at the bottom. Other than the --- split, the content of the docstring is left as is and should be valid myst markdown.

Regarding plotly, all currenly implemented plots already work, and I have also added initial support for the arviz-clean style. Now az.style.use in no longer an alias to matplotlib plt.style.use but instead sets that style as the default for all installed backends with style/template support. This still needs to be documented though.

@aloctavodia aloctavodia merged commit ba28120 into main Jul 25, 2024
4 checks passed
@aloctavodia aloctavodia deleted the plotly_poc branch July 25, 2024 13:21
@aloctavodia
Copy link
Contributor

This is really awesome, so I am merging. I have a few nitpicks, that I am listing here. I can open issues later.

Marginal distribution comparison plot --- point-estimate overlaps (plotly okish, but not matplotlib), titles overlaps (plotly)
ECDF plot --- plotly each variable has a different color, but the same for matplotlib and bokeh
Trace and distribution plot -- plotly looks very tall compared to matplotlib
Trace plot -- plotly titles overlap
My first impression is that we should extend style.py so we have some of the functionalities available in matplotlib, at least being able to list the available styles.

@OriolAbril
Copy link
Member Author

Issues will be great. Some of them will be fixed by #67 I think (as once implemented all backends should get roughly the same size, and definitely the same aspect ratio).

The title overlap is most probably bad plotly usage on my side 😅, and the different colors already have an open issue #56 as this is also an issue in matplotlib when we use plot dist to overlay things on the same plot (automatic cycling works differently in the backends: matplotlib cycles automatically within axes, bokeh does no automatic cycling and plotly cycles automatically within figures)

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