Skip to content

Commit

Permalink
Version 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Theomat committed Aug 6, 2024
1 parent 4bff7bd commit 50f0c7c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ This project on [PyPi](https://pypi.org/project/pltpublish/)|[GitHub](https://gi

Utility package that takes care of configuring Matplotlib for publication-ready figures!


## Easy to use

**Before**                            **After**
Expand All @@ -25,6 +24,7 @@ plt.savefig("my_fig.eps") > pub.save_fig("my_fig.eps")
- `setup` calls all `setup_*` methods
- `setup_colorblind` configures matplotlib to use a colorblind palette
- `setup_latex_fonts` configures matplotlib to use LaTeX fonts
- `save_fig` acts like `pyplot.savefig` but guarantees a minimum dpi, that the grid is on and removes outer white space
- `set_size_pixels` enables to set the size of an existing figure in pixels
- `save_fig` acts like `pyplot.savefig` but guarantees that the grid is on and removes outer white space and also enables to scale up or down the figure before saving
- `extract_legend_as_figure` extracts the legend of your figure and plots it on another new figure
- `layout_for_subplots` finds automatically a good layout given the number of plots you have to plot on the same figure
26 changes: 19 additions & 7 deletions examples/sinusoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,43 @@


def plotting() -> None:
plt.figure()
X = [x / 100 * math.pi for x in range(100)]
Y1 = [math.sin(x) for x in X]
plt.plot(X, Y1, label=r'$\sin(x)$')
plt.plot(X, Y1, label=r"$\sin(x)$")
Y2 = [math.cos(x) for x in X]
plt.plot(X, Y2, label=r'$\cos(x)$')
Y3 = [.25 * math.sin(x) + .5 * math.cos(4*x) for x in X]
plt.plot(X, Y3, label=r'$\frac{1}{4}\sin(x)+\frac{1}{2}\cos(4x)$')
Y4 = [.5 * math.sin(2*x)**2 + 1/3 * math.cos(4*x) for x in X]
plt.plot(X, Y4, label=r'$\frac{1}{2}\sin(2x)^2+\frac{1}{3}\cos(4x)$')
plt.plot(X, Y2, label=r"$\cos(x)$")
Y3 = [0.25 * math.sin(x) + 0.5 * math.cos(4 * x) for x in X]
plt.plot(X, Y3, label=r"$\frac{1}{4}\sin(x)+\frac{1}{2}\cos(4x)$")
Y4 = [0.5 * math.sin(2 * x) ** 2 + 1 / 3 * math.cos(4 * x) for x in X]
plt.plot(X, Y4, label=r"$\frac{1}{2}\sin(2x)^2+\frac{1}{3}\cos(4x)$")
plt.xlabel("Angle in radians")
plt.ylabel("Something interesting")
plt.legend()


def classic() -> None:
plt.figure()
plotting()
plt.savefig("classic.png")


def pltpublish() -> None:
pub.setup()
plt.figure()
plotting()
pub.save_fig("pltpublish.png")


def set_size() -> None:
pub.setup()
plt.figure()
pub.set_size_pixels(800, 600)
plotting()
pub.save_fig("pltpublish_800x600.png", scale=2)


if __name__ == "__main__":
# in that order
classic()
pltpublish()
set_size()
3 changes: 2 additions & 1 deletion pltpublish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
setup,
setup_colorblind,
setup_latex_fonts,
set_size_pixels,
layout_for_subplots,
)

__version__ = "1.0.0"
__version__ = "1.0.2"
4 changes: 3 additions & 1 deletion pltpublish/pltpublish.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
from typing import Any, Tuple
import sys
from typing import Any, Optional, Tuple

import matplotlib
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -144,5 +145,6 @@ def layout_for_subplots(nplots: int, screen_ratio: float = 16 / 9) -> Tuple[int,
"setup",
"setup_colorblind",
"setup_latex_fonts",
"set_size_pixels",
"layout_for_subplots",
]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pltpublish"
version = "1.0.0"
version = "1.0.2"
description = "Utility package that takes care of configuring Matplotlib for publication-ready figures!"
authors = ["Théo Matricon <theomatricon@gmail.com>"]
license = "MIT"
Expand Down

0 comments on commit 50f0c7c

Please sign in to comment.