(matplotlylib) Make convert_dash more robust to changes in matplotlib. #938
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Now handles the case where the dashes are scaled, have floating-point values, or were customized with
dashes=(N,M)
.Additional context: I was trying to use
mpl_to_plotly
in a jupyter notebook (python 3.6.3, matplotlib 2.1.2), and converting a plot with a non-solid line style (e.g linestyle='--') would still return a solid plot. It turns out that theDASH_MAP
inmpl_tools.py
has a set of hardcoded values, which I imagine changed with recent versions ofmatplotlib
.With linestyle='--', I was getting values like '7.4,3.2' which would not match the
6,6
of the match. Forcingdash=(6,6)
would still not work because thempl_dash
string would become '6.0,6.0`, and still not match '6,6'.I am new to plotly and matplotlib, so maybe I missed something, but this PR solves the issue for me, and all the line styles are now kept during the conversion, including custom
dashes
. It should also be somewhat robust to future changes.