I am working on dynamically changing matplotlib style sheet during runtime. I have initialized a class for matplotlib widget and chosen two styles from matplotlib style sheet reference - let's say default and dark_background styles.
Refer link for matplotlib style sheet : https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html.
I have initialized a push button configured to switch between the two styles.
When the button is toggled, it gets detected. I have a function with input from the push button toggle and its input is used to enable the matplotlib style sheet.
When the code is executed, when I toggle the push button, the matplotlib style sheet change does not apply.
Here is the code snippet for reference:
def style_select(self):
if self.style == "dark":
plt.style.use('dark_background')
else:
plt.style.use('default')
self.canvas.draw()
pass
you need to place your cutom mplstyle file in the same directory where Matplotlib stores its mplstyle files:
./Lib/site-packages/matplotlib/mpl-data/stylelibthen set stylesheet in your code using the cutom mplstyle file name without its extension:plt.style.use('mystyle')