Skip to content

breaking change in dash verification in 2.0.0 #8141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
amueller opened this issue Feb 24, 2017 · 8 comments
Closed

breaking change in dash verification in 2.0.0 #8141

amueller opened this issue Feb 24, 2017 · 8 comments
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@amueller
Copy link
Contributor

amueller commented Feb 24, 2017

This no longer works:

import matplotlib.pyplot as plt
from cycler import cycler
plt.rc('axes', prop_cycle=(
    cycler('dashes', [(None, None), (None, None), (6, 6), (3, 3), (1.5, 1.5)])))

but it used to work in 1.5.

Now it yields

TypeError: float() argument must be a string or a number, not 'NoneType'

@amueller
Copy link
Contributor Author

amueller commented Feb 24, 2017

I would appreciate a work-around, too. The intention is that the first two lines are solid, and then we get dashes.

@amueller
Copy link
Contributor Author

amueller commented Feb 24, 2017

Using a small positive number is a decent workaround for me for now:

import matplotlib.pyplot as plt
from cycler import cycler
% matplotlib inline
import numpy as np

plt.rc('axes', prop_cycle=(cycler('dashes',
                                  [(1, 0.01), (1, 0.01), (6, 6), (3, 3), (1.5, 1.5)])))

for i in range(5):
    plt.plot(np.sin(np.linspace(-5, 5, 100) + i))

image

In case anyone wonders wtf I'm doing here: In b/w, I feel like we can distinguish two solid lines by color, but for more than two lines I want dash-patterns.

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Feb 24, 2017
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Feb 24, 2017
@afvincent
Copy link
Contributor

An alternative workaround may be to use the plot kwarg linestyle (or ls) instead of the dashes one. One can then use named line styles ('solid' or '-' for example), or (offset, on-off ink sequence). It is a bit more verbose but the following script seems to be working properly on master

import matplotlib.pyplot as plt
from cycler import cycler
import numpy as np

plt.rc('axes', prop_cycle=(cycler('linestyle', ['-', '-', (0, (6, 6)),
                                                (0, (3, 3)), (0, (1.5, 1.5))]))
       )

for i in range(10):
    plt.plot(np.sin(np.linspace(-5, 5, 100) + i))

PS : @amueller is it normal that there are 6 lines on your picture while plt.plot is only called 5 times in your example script?

@amueller
Copy link
Contributor Author

I changed the script but then didn't reupload the picture ;)

@amueller
Copy link
Contributor Author

Thanks for your suggestion. That seems cleaner.

@afvincent
Copy link
Contributor

The issue still has to be fixed but at least this workaround should avoid using (1, 0.01) dashes when the meaning is "a solid line please" ;).

@dkua
Copy link
Contributor

dkua commented Mar 2, 2017

Was just looking through the Issues page for fun and decided to try my hand at fixing this.

Ran the code from the OP using different versions of 1.5.x and 2.0.x and this is definitely only a bug that exists in 2.0.x. So I ran the code through pdb and found that it was failing on line 316 in validate_nseq_float() of rcsetup.py. A quick looks through the 1.5.x codebase shows that validate_nseq_float() exists there so it's not the original cause of this bug.

Some more diving with pdb and I found that validate_nseq_float() was being called on the cycler() input in OP on line 861 of rcsetup.py in validate_cycler(). This line was calling the _prop_validators dictionary using "dashes" as the key and the list of five tuples as the vals which came from the OP code. The "dashes" entry in the _prop_validators dict corresponds to the validate_dashlist callable on line 698 which is a listified version of validate_nseq_float(). Looking through the 1.5.x code again it seems that this extra cycle "dashlist" validation code doesn't exist there so it seems to be the reason that the OP code is failing. Checking git blame on line 698 I find that this extra validation code comes from commit 9ee5f8d which landed in 2.0.x.

validate_nseq_float(s) checks that the given finite sequence s contains only floats but looking at the documentation for dashes, (None, None) is valid input so using a float-only validator is a regression. Then the solution to this bug seems to be either:

  1. Change validate_nseq_float to allow Nones which I have done in dkua@353aceb
  2. Add an additional validator for finite sequences of floats and Nones which I have done as validate_nseq_float_or_None in dkua@72120b3 and dkua@7916b3a

I've tested both of those options manually on my computer using the OP code and they both produce a correct looking plot without crashing as in 1.5.x. I can add in a quick test and submit one of the options as a PR for this issue but have not decided which option is better and want to ask the matplotlib team first. The first option seems suboptimal since validate_nseq_float() is used elsewhere in the code but the second option adds in extra near-duplicate code. Either option it seems the int equivalent of these validators should also be changed since this might come up for them later on too (maybe?).

Please let me know what y'all think.

kenmaca added a commit to kenmaca/matplotlib that referenced this issue Mar 4, 2017
Validators for dashed linestyles now allow None as an allowed value along with floats through optional `allow_none` kwarg in validate_nseq_float. Other validators that use validate_nseq_float arent affected
@kenmaca
Copy link
Contributor

kenmaca commented Mar 5, 2017

I've submitted a PR that should fix this issue by allowing None values only when validating dashed line styles via validate_nseq_float with a new allow_none flag flipped on, while retaining the original behaviour for other validators using validate_nseq_float to avoid any breaking changes.

Adding another validator just for dashed lines seems redundant, IMO.

@QuLogic QuLogic mentioned this issue Mar 5, 2017
@NelleV NelleV closed this as completed in be72573 Mar 8, 2017
NelleV added a commit that referenced this issue Mar 8, 2017
Issue #8141: Dash validator allowing None values in addition to floats
ngoldbaum pushed a commit to ngoldbaum/matplotlib that referenced this issue Mar 13, 2017
Validators for dashed linestyles now allow None as an allowed value along with floats through optional `allow_none` kwarg in validate_nseq_float. Other validators that use validate_nseq_float arent affected
kenmaca added a commit to kenmaca/matplotlib that referenced this issue Mar 14, 2017
Issue matplotlib#8141: Dash validator allowing None values in addition to floats
ibnIrshad pushed a commit to ibnIrshad/matplotlib that referenced this issue Mar 18, 2017
* Update documentation of stem

changed here: matplotlib@d68662a

* Update vlines example with axes wide lines.

* Clean up BoundaryNorm docstring

* Document what happens when ncolors > bins

* BoundaryNorm docstring clarification

* BoundaryNorm docstring formatting

* Added set_xlim and set_ylim check for non-finite limit values

* FIX: masked images with interpolation

When determining which pixels to mask in the resampled image, if _any_
contribution to final value comes from a masked pixel, mask the
result.

Due to Agg special-casing the meaning of the alpha channel,
the interpolation for the mask channel needs to be done separately.
This is probably a template for doing the over/under separately.

print out exact hash on travis

* Cleaned up invalid axis limit warning text

* FIX tick label alignment can now be specified

This patch adds two new rcParams allowing to set label alignment. The sole
reason for the existance of these new parameters is to allow user to reset the
style to before 2.0 for testing purposes. More specifically, ytick horizontal
alignement was changed in a non backward compatible way. xtick vertical
alignement was added for API consistency.

closes matplotlib#7905

* MAINT created a new private _classic_test stylesheet

This allows the public classic stylesheet to be 'more' backward compatible

* FIX small nitpicks

* Template-ize visual_tests.py.

* Pass missing variable to format string.

* Simplify dictionary access in visual_tests.py.

* PEP8 visual_tests.py.

* Sort results in visual test HTML.

This makes the result a bit more reproducable and comparable.

* Don't start a browser for visual tests on CI.

Travis may or may not have a browser installed, but AppVeyor definitely
does, so this saves a tiny bit of processing power per run.

* Move visual_tests into tools.

* Add tools directory to pep8.

* pgf: Fix invalid arguments passed to pdftocairo.

This breaks saving PNG when using the PGF backend.

Fixes matplotlib#8121.

* MAINT Backporting of matplotlib#7995.

Set sticky_edges correctly for negative height bar().

* Small docstring fixes

* merge fill_demo and fill_demo_features

* move imports below title

* Merge docstring coherent

* Plot errorbars if fmt=='none'

* Add test for fmt=='none'

* Fix small spelling mistake

* Check plotted bars are color C0

* Add cleanup to new test

* Simplify multicolored_line example

* Move multicolored_line example

* Small fixes

* Put boundarynorm example back in

* Add autoclass entry for Artist API doc.

Adding an autoclass entry in the Artist API ensures that that class
appears in the intersphinx `build/html/object.inv`, as can be checked by
```
"matplotlib.artist.Artist" in (
    sphinx.ext.intersphinx.read_inventory(
        open("build/html/objects.inv", "rb"), None, lambda *args: None)[
            "py:class"])
```
(now returns True).

This allows other projects to link to that class in their docs using
```
`Artist` <matplotlib.artist.Artist>
```

This possibility used to be present, but disappeared when the Artist API
doc got refactored.  (Other classes that appear in the API docs are fine
as they already use autoclass.)

* Merge pull request matplotlib#8171 from afvincent/typo_eventplot_docstring

DOC: Fix small typos in 'eventplot' docstring

* Fix layout of spectrum_demo.py

* Beautified spectrum_demo.py a little more.

* Added plot titles to spectrum_demo.py

* Correct theta values when drawing a non-circular ellipse

Make arcs work with units

Add api change not for elliptical notes

Add background ellipse and extra line to test

Remove pdf and svg tests for arc angles

* Fix small typo in api change

* add gitter link in README

* add a line to README that explains use of gitter

* Fixes matplotlib#8141
Validators for dashed linestyles now allow None as an allowed value along with floats through optional `allow_none` kwarg in validate_nseq_float. Other validators that use validate_nseq_float arent affected

* Replace second instance of gitter badge with a link

* TST: Enable cache directories on AppVeyor.

* Use secure links to FreeType tarballs.

* Try harder to cache FreeType tarball on Python 2.

* TST: Always delete extra cache files on Travis.

Note, we don't need to do this on AppVeyor because the cache directories
are different.

* add parameter and test

* implemented label rotation

* pep8 fix

* DOC moved autowarp_demo to sphinx-gallery compatible docstring

* DOC spines example are now sphinx-gallery compliant

* DOC all tick labels examples are now sphinx-gallery compatible

* DOC moved text_demo_fontdict to sphinx-gallery compatible docstring

* TST: skip fc-list related tests if not installed

* DOC FIX removed a blank line from an example

* DOC moving showcase examples to sphinx-gallery

* Plural of axis is axes

* add early check for dot binary (from graphviz) when building the doc

* Clarify segment array shape

* Make ginput dostring into a numpydocstring

Small fixes

Add default value for npoints

Suggested changes to ginput docstring

Better description of ginput return

Put summary line by itself at the top

Add in missing full stops

* Implement Path.intersects_bbox in C++ to speed up legend positioning.

* DOC removed/added blankspace

* DOC fixe small typos and blank lines

* DOC capitalized firefox

* renamed flag to 'rotatelabels'; fix vertical alignment

* Update spines_demo.py

* MEP12 alignment_test

* Move alignment_test example

* MEP12 and simplify ganged_plots example

* Move ganged plots example

* pep8 fix

* added headers

* added/fixed headers

* DOC removed redundant call to plt.show()

* DOC added docstring to vline-hline example.

* fix gitter badge

* Set subplot spacing to zero

* Clean up description wording

* fix rst markup

* Fix pep8 violation

* Fix example description phrasing

* Remove image with non-free color calibration profile

The example that used to use this image was remove already in commit 9692c31.

This closes matplotlib#8034.

* MAINT Backporting of matplotlib#8241: remove possible non-free image

* Ignore invisible axes in computing tight_layout.

* combining and updating 2d hist examples

* consolidating histogram examples and moving to SG folder

* Memoize parse_fontconfig_pattern; speeds up test suite by ~1min.

On my laptop this patch drops the duration of the test suite from 604s
to 554s (with the inkscape patch on as well).

* addressing small change comments

* Contouring 1x1 array (issue 8197)

* another attempt; add a test

* Set __name__ for list validators in rcsetup.

This avoids having many validators all named `f`, which makes profiling
a bit difficult (it appears that repeated validation of rcparams when
resetting the style at the beginning of each test instance contributes
quite a bit to the total test time).  Instead, the list validator
based on scalar validator function `validate_foo` is now `__name__`d
`validate_foolist`, and the list validator based on scalar validator
class `ValidateFoo` is now `__name__`d `ValidateFooList`.

* TST: fail on missing baseline file

* re-add conditional check.

* DOC moved spines examples sphinx-gallery

* Use sys.executable -msphinx instead of sphinx-build.

* More robust type checking in '_validate_linestyle', on both Py2 and Py3

* tests now depend on python version to check cases with bytes args

* DOC changes in travis's build environment

* DOC removed duplicate appveyor py3.5 environment

* CI: travis runs documentation build and mac osx only on merge with master

* MAINT remove py.test from our travis build

* FIX appveyor doesn't need option USE_PYTEST anymore

* append test images.

* removed obsolete license.py file

* DOC moved changelog to the documentation

* DOC fix broken links

* MAINT moved some maintenance and helper python scripts to tools/

* FIX path in boilerplate.py

* Small header comment fixes

* Removes OldScalarFormatter

* Renaming file to scalarformatter_demo.py

* Renaming to plot_scalarformatter.py

* Adds title and description

* changing name in backend_driver.py

* Inkscape shell mode.

* Fix minimum sphinx version in doc-requirements.txt.

* Correcting typos and moving file to ticks and spines

* STY: fix whitespace in the tests

* Remove executable bit from examples and headers.

The vast majority of examples do not have the executable bit set, so
just make everything consistent.

Also remove `#!/usr/bin/env python` where appropriate.

* DOC shapes and collections is fully SG compatible

* Use neutral pronoun in docs.
QuLogic pushed a commit to QuLogic/matplotlib that referenced this issue Mar 27, 2017
…8141

Issue matplotlib#8141: Dash validator allowing None values in addition to floats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

No branches or pull requests

5 participants