LovelyPlots
LovelyPlots is a Python library that provides a collection of Matplotlib styles specifically designed to format plots for scientific papers, theses, and reports. It aims to make plots professional, consistent, and aesthetically pleasing with minimal effort. The current version is 1.0.2, and releases are generally driven by bug fixes or the addition of new styles.
Common errors
-
ValueError: 'lovelyplots' is not a valid style sheet
cause Since LovelyPlots v1.0.1, the `lovelyplots` package must be explicitly imported for its styles to be registered with Matplotlib.fixAdd `import lovelyplots` at the top of your script, before any calls to `matplotlib.pyplot` functions or `plt.style.use()`. -
ModuleNotFoundError: No module named 'lovelyplots'
cause The `lovelyplots` library has not been installed in your current Python environment.fixInstall the package using pip: `pip install lovelyplots`.
Warnings
- breaking Starting from version 1.0.1, it is mandatory to explicitly `import lovelyplots` at the beginning of your script. Failing to do so will result in Matplotlib not finding the 'lovelyplots' styles.
- gotcha LovelyPlots requires Matplotlib to be installed. Ensure your Matplotlib version is compatible with LovelyPlots (currently `matplotlib>=3.3`).
Install
-
pip install lovelyplots
Imports
- lovelyplots
import matplotlib.pyplot as plt plt.style.use('lovelyplots')import lovelyplots import matplotlib.pyplot as plt plt.style.use('lovelyplots')
Quickstart
import lovelyplots # Required since v1.0.1
import matplotlib.pyplot as plt
import numpy as np
# Apply one of the lovelyplots styles (e.g., 'lovelyplots', 'paper', 'notebook', 'presentation')
plt.style.use('lovelyplots')
# Example plot
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x) + np.cos(x**2)
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.plot(x, y, label='A Lovely Plot Example')
ax.set_title('My Scientific Plot')
ax.set_xlabel('Time (s)')
ax.set_ylabel('Amplitude (a.u.)')
ax.legend()
fig.tight_layout()
# plt.show() # Uncomment to display the plot
# fig.savefig('my_lovely_plot.png', dpi=300) # Uncomment to save the plot