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
Set style for figure or axes in object oriented way. #20131
Comments
That won't work as you expect. Most styles are applied as defaults to artists at creation, so your plot will already have the old style. It's not possible to retroactively change the styles of artists after they have been added to the figure, and trying to make it possible would be needlessly complicated. |
Thank you for your explanation, @jklymak. I know matplotlib artists are set at the creation, and this is why I ask for a 'new featue'. There is no easy solutions for this, but I wish matplotlib will able to do this in the 4.0 version. I will also look into the code and think about the solution. |
I guess my point is this is a new architecture that, I agree, there is sometimes tension to adopt. I think doing so would be a mistake however, because it is much less explicit and we will be chasing down edge cases ad-naseum. Matplotlib is based off Matlab, and the paradigm was very explicit. You put an artist on the figure, and if you want to change it, you take the handle to the artist and you change it there. The desire for a more implicit paradigm, where rcParams only get resolved at draw time, comes up all the time, but it just leads to confusion. i.e. suppose I do
should I then change the artist You have a second request, which is to make the style sheet apply separately to different axes. I think that works already with context managers? Its a little awkward, but it is a little strange to change styles in the middle of a figure: import matplotlib.pyplot as plt
fig = plt.figure()
gs = fig.add_gridspec(1,2)
with plt.style.context('ggplot'):
ax1 = fig.add_subplot(gs[0,0])
ax1.plot(range(10))
ax2 = fig.add_subplot(gs[0,1])
ax2.plot(range(10))
plt.show() |
Just wanted to quickly say I think this would be a great feature. My use case is setting the style on a specific figure. Perhaps setting the style when a figure is created (ie. not modifying it after creation) would be a good and easier first step to take in this direction. |
Problem
Proposed Solution
ax.set_style()
andfig.set_style()
method. Then we can customize styles in the way below.ax.style.use()
ax.style.context()
The text was updated successfully, but these errors were encountered: