matplotlib-pyodide icon indicating copy to clipboard operation
matplotlib-pyodide copied to clipboard

setting plt.rcParams['figure.figsize'] does not work.

Open PrParadox opened this issue 1 year ago • 1 comments

I tried to make matplotlib responsive by doing this little trick

from js import window 
plt.rcParams['figure.figsize'] = [window.innerWidth*window.devicePixelRatio, 6] 
plt.rcParams["figure.dpi"] = window.devicePixelRatio

However, it does not work. Interestingly, even if I hardcode figsize, it still does not respect my parameters. What should be done? (the figure is interactive. i.e it has a slider)

PrParadox avatar Jan 18 '24 19:01 PrParadox

I'll second this as an issue I ran across while using the matplotlib_pyodide.html5_canvas_backend module.

If I set a parameter in rcParams, then the first time I generate a graph the new dimensions are being used. However, subsequent calls with different dimensions did not change how the graph was created.

import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (20,3)

That said, if I directly set a value for the figure, then the graph would disappear but the additional controls would remain.

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.ylabel('Magic Numbers')

fig = plt.figure(figsize=(10, 10))
plt.show()

coatless avatar Feb 21 '24 08:02 coatless