Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from nschloe/zorder
Browse files Browse the repository at this point in the history
adapt zorder
  • Loading branch information
nschloe authored Apr 22, 2020
2 parents c0fa020 + 0795f20 commit 68e5c60
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cpl.plot(x1, y1, "CRV-27")
x2 = numpy.linspace(0.0, 3.0, 100)
y2 = 1.6 * x2 / (x2 + 1)
y2 += 0.1 * numpy.random.rand(len(y2))
cpl.plot(x2, y2, "CRV27*")
cpl.plot(x2, y2, "CRV-27*")

cpl.show()
# cpl.savefig("ex1.svg", transparent=True, bbox_inches="tight")
Expand All @@ -58,6 +58,7 @@ Further reading:

* [Randal S. Olson's blog entry](http://www.randalolson.com/2014/06/28/how-to-make-beautiful-data-visualizations-in-python-with-matplotlib/)
* [prettyplotlib](https://github.com/olgabot/prettyplotlib)
* [Wikipedia: Chartjunk](https://en.wikipedia.org/wiki/Chartjunk)


### Testing
Expand Down
2 changes: 1 addition & 1 deletion cleanplotlib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .__about__ import __version__
from .main import multiplot, plot, show, savefig
from .main import multiplot, plot, savefig, show

__all__ = ["__version__", "multiplot", "plot", "show", "savefig"]
19 changes: 13 additions & 6 deletions cleanplotlib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,24 @@ def _move_min_distance(targets, min_distance, eps=1.0e-5):


def multiplot(
x, y, labels, min_label_distance="auto", ygrid=True, fontsize=14, height=5
x,
y,
labels,
min_label_distance="auto",
ygrid=True,
fontsize=14,
height=5,
alpha=1.4,
):
p = [plt.plot(xx, yy) for xx, yy in zip(x, y)]
n = len(x)
p = [plt.plot(xx, yy, zorder=n - k) for k, (xx, yy) in enumerate(zip(x, y))]

fig = plt.gcf()
fig.set_size_inches(12 / 9 * height, height)

if min_label_distance == "auto":
# Make sure that the distance is alpha times the fontsize. This needs to be
# translated into axes units.
alpha = 1.7
fig_height = fig.get_size_inches()[0]
ax = plt.gca()
ax_pos = ax.get_position()
Expand Down Expand Up @@ -120,12 +127,12 @@ def multiplot(
plt.xticks(fontsize=fontsize)
plt.yticks(fontsize=fontsize)

if ygrid:
plt.grid(axis="y", dashes=(10, 10), lw=0.5, color="black", alpha=0.3)

# Don't waste space
plt.autoscale(tight=True)

if ygrid:
plt.grid(axis="y", dashes=(10, 10), lw=0.5, color="black", alpha=0.3)

# Add "legend" entries.
targets = [yy[-1] for yy in y]
idx = _argsort(targets)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = cleanplotlib
version = 0.1.0
version = 0.1.1
author = Nico Schlömer
email = [email protected]
description = Clean line plots
Expand Down
2 changes: 1 addition & 1 deletion test/test_cleanplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_plot():
x2 = numpy.linspace(0.0, 3.0, 100)
y2 = 1.6 * x2 / (x2 + 1)
y2 += 0.1 * numpy.random.rand(len(y2))
cpl.plot(x2, y2, "CRV27*")
cpl.plot(x2, y2, "CRV-27*")

cpl.show()
# cpl.savefig("ex1.svg", transparent=True, bbox_inches="tight")
Expand Down

0 comments on commit 68e5c60

Please sign in to comment.