Skip to content

Commit

Permalink
Merge pull request nschloe#18 from nschloe/colors
Browse files Browse the repository at this point in the history
Colors
  • Loading branch information
nschloe authored Feb 25, 2018
2 parents d493207 + 342daf2 commit 6a30d49
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 49 deletions.
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
working_directory: ~/perfplot
docker:
- image: ubuntu:17.10
- image: ubuntu:18.04
steps:
- run: apt-get update
- run: apt-get install -y git python3-pip
Expand All @@ -18,8 +18,7 @@ jobs:
- run: make README.rst
- run: python3 setup.py check -r -s
# The actual test
- run: pylint perfplot/
- run: pylint test/*.py
- run: pylint setup.py perfplot/ test/*.py
- run: cd test/ && MPLBACKEND=Agg pytest --cov perfplot
# submit to codecov
- run: apt-get install -y curl
Expand Down
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[MESSAGES CONTROL]

disable=
bad-continuation,
invalid-name,
missing-docstring,
no-member,
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# perfplot

[![Build Status](https://travis-ci.org/nschloe/perfplot.svg?branch=master)](https://travis-ci.org/nschloe/perfplot)
[![CircleCI](https://img.shields.io/circleci/project/github/nschloe/perfplot/master.svg)](https://circleci.com/gh/nschloe/perfplot/tree/master)
[![codecov](https://img.shields.io/codecov/c/github/nschloe/perfplot.svg)](https://codecov.io/gh/nschloe/perfplot)
[![Codacy grade](https://img.shields.io/codacy/grade/32994ce499db42059777d42edcfce900.svg)](https://app.codacy.com/app/nschloe/perfplot/dashboard)
[![PyPi Version](https://img.shields.io/pypi/v/perfplot.svg)](https://pypi.python.org/pypi/perfplot)
[![GitHub stars](https://img.shields.io/github/stars/nschloe/perfplot.svg?style=social&label=Stars)](https://github.com/nschloe/perfplot)

Expand Down
2 changes: 1 addition & 1 deletion example/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import perfplot

perfplot.show(
setup=lambda n: numpy.random.rand(n),
setup=numpy.random.rand,
kernels=[
lambda a: numpy.c_[a, a],
lambda a: numpy.stack([a, a]).T,
Expand Down
2 changes: 1 addition & 1 deletion perfplot/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
__copyright__ = \
u'Copyright (c) 2017-2018, {} <{}>'.format(__author__, __author_email__)
__license__ = 'License :: OSI Approved :: MIT License'
__version__ = '0.2.7'
__version__ = '0.2.8'
__status__ = 'Development Status :: 5 - Production/Stable'
2 changes: 1 addition & 1 deletion perfplot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
pass
else:
if pipdate.needs_checking(__name__):
print(pipdate.check(__name__, __version__))
print(pipdate.check(__name__, __version__), end='')
38 changes: 22 additions & 16 deletions perfplot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ def save(filename, *args, **kwargs):


# pylint: disable=too-many-arguments,too-many-locals,too-many-branches
def plot(
setup, kernels, n_range,
labels=None,
xlabel=None,
title=None,
repeat=100,
logx=False,
logy=False,
automatic_order=True,
equality_check=numpy.allclose
):
def plot(setup, kernels, n_range,
labels=None,
colors=None,
xlabel=None,
title=None,
repeat=100,
logx=False,
logy=False,
automatic_order=True,
equality_check=numpy.allclose):
if labels is None:
labels = [k.__name__ for k in kernels]

# Estimate the timer granularity by measuring a no-op.
noop_time = timeit.repeat(repeat=10, number=100)
granularity = min(noop_time) / 100
Expand All @@ -42,7 +44,9 @@ def plot(
reference = kernels[0](out)
for k, kernel in enumerate(tqdm(kernels)):
if equality_check:
assert equality_check(reference, kernel(out))
assert equality_check(reference, kernel(out)), \
'Equality check fail. ({}, {})' \
.format(labels[0], labels[k])
# Make sure that the statement is executed at least so often that
# the timing exceeds 1000 times the granularity of the clock.
number = 1
Expand Down Expand Up @@ -90,18 +94,20 @@ def plot(
x = n_range
T = numpy.min(timings, axis=2)

if labels is None:
labels = [k.__name__ for k in kernels]
if colors is None:
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color'][:len(labels)]

if automatic_order:
# Sort T by the last entry. This makes the order in the legend
# correspond to the order of the lines.
order = numpy.argsort(T[:, -1])[::-1]
T = T[order]
labels = [labels[i] for i in order]
colors = [colors[i] for i in order]

for t, label in zip(T, labels):
plotfun(x, t, label=label)
for t, label, color in zip(T, labels, colors):
plotfun(x, t, label=label, color=color)
if xlabel:
plt.xlabel(xlabel)
if title:
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-
#
import os
from setuptools import setup, find_packages
import codecs

from setuptools import setup, find_packages

# https://packaging.python.org/single_source_version/
base_dir = os.path.abspath(os.path.dirname(__file__))
about = {}
with open(os.path.join(base_dir, 'perfplot', '__about__.py'), 'rb') as f:
# pylint: disable=exec-used
exec(f.read(), about)


Expand All @@ -17,7 +19,7 @@ def read(fname):
os.path.join(os.path.dirname(__file__), fname),
encoding='utf-8'
).read()
except Exception:
except IOError:
content = ''
return content

Expand Down
46 changes: 23 additions & 23 deletions test/perfplot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ def test():
kernels = [lambda a: numpy.c_[a, a]]
r = [2**k for k in range(4)]
perfplot.show(
setup=numpy.random.rand,
kernels=kernels, labels=['c_'], n_range=r, xlabel='len(a)'
)
setup=numpy.random.rand,
kernels=kernels, labels=['c_'], n_range=r, xlabel='len(a)'
)
perfplot.show(
setup=numpy.random.rand,
kernels=kernels, labels=['c_'], n_range=r, xlabel='len(a)',
logx=True, logy=False
)
setup=numpy.random.rand,
kernels=kernels, labels=['c_'], n_range=r, xlabel='len(a)',
logx=True, logy=False
)
perfplot.show(
setup=numpy.random.rand,
kernels=kernels, labels=['c_'], n_range=r, xlabel='len(a)',
logx=False, logy=True
)
setup=numpy.random.rand,
kernels=kernels, labels=['c_'], n_range=r, xlabel='len(a)',
logx=False, logy=True
)
perfplot.show(
setup=numpy.random.rand,
kernels=kernels, labels=['c_'], n_range=r, xlabel='len(a)',
logx=True, logy=True
)
setup=numpy.random.rand,
kernels=kernels, labels=['c_'], n_range=r, xlabel='len(a)',
logx=True, logy=True
)
return


Expand All @@ -33,9 +33,9 @@ def mytest(a):
kernels = [mytest]
r = [2**k for k in range(4)]
perfplot.show(
setup=numpy.random.rand,
kernels=kernels, n_range=r, xlabel='len(a)'
)
setup=numpy.random.rand,
kernels=kernels, n_range=r, xlabel='len(a)'
)
return


Expand All @@ -45,9 +45,9 @@ def mytest(a):
kernels = [mytest]
r = [2**k for k in range(4)]
perfplot.save(
'out.png',
setup=numpy.random.rand,
kernels=kernels, n_range=r,
xlabel='len(a)', title='mytest'
)
'out.png',
setup=numpy.random.rand,
kernels=kernels, n_range=r,
xlabel='len(a)', title='mytest'
)
return

0 comments on commit 6a30d49

Please sign in to comment.