Bug Description / Observed Behavior
Prettyplot doesn't reset the matplotlib environment the second time it is imported and run.
Let's say you want to use latex in your prettyplots. You'll run:
mpl.rcParams.update({'text.usetex': True,}),
Make your prettyplot, and then, to be a good samaritan, you'll clean the matplotlib environment to revert it for future standard plots without latex (or prettyplot):
mpl.rcParams.update(mpl.rcParamsDefault).
Now, if you try to reimport and rerun prettyplot, the plot is no longer pretty. I believe this is due to import caching--it seems that prettyplot modifies the matplotlib rcParams upon import, instead of when run. The second time you import prettyplot, python doesn't modify the rcParams, since the import is already cached.
Steps to Reproduce
- Make a plot with prettyplot
- Reset mpl.rcParams
- Rerun the script (without restarting the python kernel)
This script suffices; try running it twice. It only plots properly the first time.
import matplotlib as mpl
import matplotlib.pyplot as plt
import aerosandbox.tools.pretty_plots as p
print("axes.facecolor:", mpl.rcParams["axes.facecolor"])
print("axes.grid:", mpl.rcParams["axes.grid"])
print("figure.dpi:", mpl.rcParams["figure.dpi"])
x = [0, 1, 2, 3]
y = [0, 1, 4, 9]
plt.figure(figsize=(4, 3))
plt.plot(x, y, marker="o", label="Data")
p.show_plot(
title="Run this cell twice",
xlabel="x",
ylabel="y",
)
mpl.rcParams.update(mpl.rcParamsDefault)
Expected Behavior
I expect prettyplot to plot prettily each time it is run, rather than depend on backend import caching mechanics to plot prettily.
System Information
- Operating System:
- Python Version: 3.11.10
- AeroSandbox Version: 4.2.8
Bug Description / Observed Behavior
Prettyplot doesn't reset the matplotlib environment the second time it is imported and run.
Let's say you want to use latex in your prettyplots. You'll run:
mpl.rcParams.update({'text.usetex': True,}),Make your prettyplot, and then, to be a good samaritan, you'll clean the matplotlib environment to revert it for future standard plots without latex (or prettyplot):
mpl.rcParams.update(mpl.rcParamsDefault).Now, if you try to reimport and rerun prettyplot, the plot is no longer pretty. I believe this is due to import caching--it seems that prettyplot modifies the matplotlib rcParams upon import, instead of when run. The second time you import prettyplot, python doesn't modify the rcParams, since the import is already cached.
Steps to Reproduce
This script suffices; try running it twice. It only plots properly the first time.
Expected Behavior
I expect prettyplot to plot prettily each time it is run, rather than depend on backend import caching mechanics to plot prettily.
System Information