[Python-modules-commits] [python-mplexporter] 123/135: BUG: fix linestyle for solid lines
Wolfgang Borgert
debacle at moszumanska.debian.org
Tue Sep 23 21:19:11 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to branch master
in repository python-mplexporter.
commit 2766ea5209b55d54f5de524180eef219e0878bbc
Author: Jake Vanderplas <vanderplas at astro.washington.edu>
Date: Fri May 2 15:38:51 2014 -0700
BUG: fix linestyle for solid lines
---
mplexporter/exporter.py | 2 +-
mplexporter/tests/__init__.py | 3 +++
mplexporter/tests/test_basic.py | 20 +++++++++-----------
mplexporter/tests/test_utils.py | 14 +++++++++++++-
mplexporter/utils.py | 32 ++++++++++++++------------------
5 files changed, 40 insertions(+), 31 deletions(-)
diff --git a/mplexporter/exporter.py b/mplexporter/exporter.py
index 19a61ec..7df899a 100644
--- a/mplexporter/exporter.py
+++ b/mplexporter/exporter.py
@@ -181,7 +181,7 @@ class Exporter(object):
ax, line.get_xydata(),
force_trans=force_trans)
linestyle = utils.get_line_style(line)
- if linestyle['dasharray'] in ['None', 'none', None]:
+ if linestyle['dasharray'] is None:
linestyle = None
markerstyle = utils.get_marker_style(line)
if (markerstyle['marker'] in ['None', 'none', None]
diff --git a/mplexporter/tests/__init__.py b/mplexporter/tests/__init__.py
index e69de29..13028d7 100644
--- a/mplexporter/tests/__init__.py
+++ b/mplexporter/tests/__init__.py
@@ -0,0 +1,3 @@
+import matplotlib
+matplotlib.use('Agg')
+import matplotlib.pyplot as plt
diff --git a/mplexporter/tests/test_basic.py b/mplexporter/tests/test_basic.py
index 25099ae..1fc7d56 100644
--- a/mplexporter/tests/test_basic.py
+++ b/mplexporter/tests/test_basic.py
@@ -1,13 +1,10 @@
-from ..exporter import Exporter
-from ..renderers import FakeRenderer, FullFakeRenderer
-
-import matplotlib
-matplotlib.use('Agg')
-import matplotlib.pyplot as plt
-
import numpy as np
from numpy.testing import assert_warns
+from ..exporter import Exporter
+from ..renderers import FakeRenderer, FullFakeRenderer
+from . import plt
+
def fake_renderer_output(fig, Renderer):
renderer = Renderer()
@@ -165,7 +162,7 @@ def test_image():
def test_legend():
fig, ax = plt.subplots()
- ax.plot([1,2,3], label='label')
+ ax.plot([1, 2, 3], label='label')
ax.legend().set_visible(False)
_assert_output_equal(fake_renderer_output(fig, FakeRenderer),
"""
@@ -178,10 +175,11 @@ def test_legend():
closing figure
""")
+
def test_legend_dots():
fig, ax = plt.subplots()
- ax.plot([1,2,3], label='label')
- ax.plot([2,2,2], 'o', label='dots')
+ ax.plot([1, 2, 3], label='label')
+ ax.plot([2, 2, 2], 'o', label='dots')
ax.legend().set_visible(True)
_assert_output_equal(fake_renderer_output(fig, FullFakeRenderer),
"""
@@ -200,8 +198,8 @@ def test_legend_dots():
closing figure
""")
+
def test_blended():
fig, ax = plt.subplots()
ax.axvline(0)
assert_warns(UserWarning, fake_renderer_output, fig, FakeRenderer)
-
diff --git a/mplexporter/tests/test_utils.py b/mplexporter/tests/test_utils.py
index 20b7aaf..8ce0f9b 100644
--- a/mplexporter/tests/test_utils.py
+++ b/mplexporter/tests/test_utils.py
@@ -1,5 +1,5 @@
from numpy.testing import assert_allclose, assert_equal
-import matplotlib.pyplot as plt
+from . import plt
from .. import utils
@@ -9,3 +9,15 @@ def test_path_data():
assert_allclose(vertices.shape, (25, 2))
assert_equal(codes, ['M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'Z'])
+
+
+def test_linestyle():
+ linestyles = {'solid': 'none', '-': 'none',
+ 'dashed': '6,6', '--': '6,6',
+ 'dotted': '2,2', ':': '2,2',
+ 'dashdot': '4,4,2,4', '-.': '4,4,2,4',
+ '': None, 'None': None}
+
+ for ls, result in linestyles.items():
+ line, = plt.plot([1, 2, 3], linestyle=ls)
+ assert_equal(utils.get_dasharray(line), result)
diff --git a/mplexporter/utils.py b/mplexporter/utils.py
index ed76206..93d34f0 100644
--- a/mplexporter/utils.py
+++ b/mplexporter/utils.py
@@ -27,20 +27,20 @@ def color_to_hex(color):
return '#{0:02X}{1:02X}{2:02X}'.format(*(int(255 * c) for c in rgb))
-def many_to_one(input_dict):
+def _many_to_one(input_dict):
"""Convert a many-to-one mapping to a one-to-one mapping"""
return dict((key, val)
for keys, val in input_dict.items()
for key in keys)
-LINESTYLES = many_to_one({('solid', '-', (None, None)): "10,0",
- ('dashed', '--'): "6,6",
- ('dotted', ':'): "2,2",
- ('dashdot', '-.'): "4,4,2,4",
- ('', ' ', 'None', 'none'): "none"})
+LINESTYLES = _many_to_one({('solid', '-', (None, None)): 'none',
+ ('dashed', '--'): "6,6",
+ ('dotted', ':'): "2,2",
+ ('dashdot', '-.'): "4,4,2,4",
+ ('', ' ', 'None', 'none'): None})
-def get_dasharray(obj, i=None):
+def get_dasharray(obj):
"""Get an SVG dash array for the given matplotlib linestyle
Parameters
@@ -48,7 +48,6 @@ def get_dasharray(obj, i=None):
obj : matplotlib object
The matplotlib line or path object, which must have a get_linestyle()
method which returns a valid matplotlib line code
- i : integer (optional)
Returns
-------
@@ -59,14 +58,11 @@ def get_dasharray(obj, i=None):
return ','.join(map(str, obj._dashSeq))
else:
ls = obj.get_linestyle()
- if i is not None:
- ls = ls[i]
-
- dasharray = LINESTYLES.get(ls, None)
- if dasharray is None:
- warnings.warn("dash style '{0}' not understood: "
- "defaulting to solid.".format(ls))
- dasharray = LINESTYLES['-']
+ dasharray = LINESTYLES.get(ls, 'not found')
+ if dasharray == 'not found':
+ warnings.warn("line style '{0}' not understood: "
+ "defaulting to solid line.".format(ls))
+ dasharray = LINESTYLES['solid']
return dasharray
@@ -245,7 +241,7 @@ def get_grid_style(axis):
dasharray=dasharray,
alpha=alpha)
else:
- return {"gridOn":False}
+ return {"gridOn": False}
def get_figure_properties(fig):
@@ -322,7 +318,7 @@ def get_legend_properties(ax, legend):
handles, labels = ax.get_legend_handles_labels()
visible = legend.get_visible()
return {'handles': handles, 'labels': labels, 'visible': visible}
-
+
def image_to_base64(image):
"""
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-mplexporter.git
More information about the Python-modules-commits
mailing list