Skip to content

Commit 524a8a0

Browse files
authored
Merge pull request #938 from nburrus/convert-dash
(matplotlylib) Make convert_dash more robust to changes in matplotlib.
2 parents cb71b64 + fafcabf commit 524a8a0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Diff for: plotly/matplotlylib/mpltools.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,21 @@ def convert_dash(mpl_dash):
5757
"""Convert mpl line symbol to plotly line symbol and return symbol."""
5858
if mpl_dash in DASH_MAP:
5959
return DASH_MAP[mpl_dash]
60-
else:
61-
return 'solid' # default
60+
else:
61+
dash_array = mpl_dash.split(',')
62+
63+
if (len(dash_array) < 2):
64+
return 'solid'
65+
66+
# Catch the exception where the off length is zero, in case
67+
# matplotlib 'solid' changes from '10,0' to 'N,0'
68+
if (math.isclose(float(dash_array[1]), 0.)):
69+
return 'solid'
6270

71+
# If we can't find the dash pattern in the map, convert it
72+
# into custom values in px, e.g. '7,5' -> '7px,5px'
73+
dashpx=','.join([x + 'px' for x in dash_array])
74+
return dashpx
6375

6476
def convert_path(path):
6577
verts = path[0] # may use this later

0 commit comments

Comments
 (0)