question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Matplotlib backend for visualization functions

See original GitHub issue

This issue proposes to implement the Matplotlib backend for the visualization functions.

Motivation

While the current visualization backend, Plotly, provides rich and interactive interfaces, the setup is sometimes hard especially when exporting figures as static ones. Specifically, the installation steps of Orca are complicated in some environments (see https://github.com/plotly/orca/issues/150 for example) or may restrict the way of package management as plotly-orca favors Conda installation.

Providing another backend such as Matpotlib may mitigate this problem, where the library does not require extra setup to output static figures and is pre-installed in some popular platforms such as Anaconda.

Alternatives

Plotly has supported Kaleido backend for static export since Plotly 4.9. Thus, we could guide users to install this backend, although it restricts the Plotly version where Optuna supports >= 4.0.0 currently.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
BenjaminBossancommented, Nov 21, 2020

If I may make a proposal regarding the public API of the matplotlib plotting functions:

It would be really nice if as a user, I were allowed to pass the ax to the plotting function. This allows me to have a greater control about the final plot. E.g., right now I cannot change the plot size or make the plot part of a larger figure with several subplots. Here is an example how I could use this feature:

...
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 2, figsize=(20, 10))

# plot results on a big figure with 2 subplots
optuna.visualization.matplotlib.plot_edf(study, ax=axes[0])
optuna.visualization.matplotlib.plot_optimization_history(study, ax=axes[1])

The default argument for ax could be None, in which case the functions do exactly the same thing as they do right now. Inside the different functions, you just need to change the code to:


def _get_edf_plot(studies: List[Study], ax: Optional[AxesSubplot] = None) -> "Axes":
    ...
    ax = ax or plt.subplots()[1]

I would also suggest not to set plt.style.use("ggplot") – why not leave that up to the user?

1reaction
ytknzwcommented, Aug 23, 2020

@toshihikoyanase Thank you for your feedback! My idea above is a rough draft, so I appreciate your detailed thoughts. I agree with both points you mentioned. I’ll work on it today and put a PR, then let’s discuss further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visualization with Matplotlib | Python Data Science Handbook
Matplotlib supports dozens of backends and output types, which means you can count on it to work regardless of which operating system you...
Read more >
Backends — Matplotlib 3.6.2 documentation
To support all of these use cases, Matplotlib can target different outputs, and each of these capabilities is called a backend; the "frontend"...
Read more >
Data Visualization using Matplotlib - GeeksforGeeks
This function creates axes object at a specified location inside a grid and also helps in spanning the axes object across multiple rows...
Read more >
Chapter 4. Visualization with Matplotlib - O'Reilly
Matplotlib supports dozens of backends and output types, which means you can count on it to work regardless of which operating system you...
Read more >
Data Visualization with Python — Matplotlib Architecture
Data visualization plays an essential role in Data Science, ... The backend layer handles all the heavy works via communicating to the toolkits...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found