X Tutup
Skip to content

Drop None from Container.get_children().#8119

Merged
NelleV merged 1 commit intomatplotlib:masterfrom
anntzer:drop-None-container-children
Feb 22, 2017
Merged

Drop None from Container.get_children().#8119
NelleV merged 1 commit intomatplotlib:masterfrom
anntzer:drop-None-container-children

Conversation

@anntzer
Copy link
Copy Markdown
Contributor

@anntzer anntzer commented Feb 21, 2017

Before the patch,

ec = plt.errorbar([1, 2], [3, 4], [5, 6], capsize=2, fmt="none")
print(ec.get_children())

would print None (corresponding to the "not drawn" line connecting the
data points), two Line2D and one LineCollection.

This patch drops the None out, as it is arguably not a child of the
Container. (It is still possible to access the individual members of
the Container by unpacking it as a tuple.)

Also reformat an overly indented piece of code in the vicinity.

Before the patch,
```
ec = plt.errorbar([1, 2], [3, 4], [5, 6], capsize=2, fmt="none")
print(ec.get_children())
```
would print `None` (corresponding to the "not drawn" line connecting the
data points), two `Line2D` and one `LineCollection`.

This patch drops the `None` out, as it is arguably not a child of the
Container.  (It is still possible to access the individual members of
the Container by unpacking it as a tuple.)

Also reformat an overly indented piece of code in the vicinity.
@phobson
Copy link
Copy Markdown
Member

phobson commented Feb 21, 2017

So now it'll return an empty list? Am I reading that right?

Containers are hardly tested. Could we add some to cover this case?

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Feb 21, 2017
@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Feb 21, 2017

@phobson Yes, yes, and go ahead :)

@dstansby
Copy link
Copy Markdown
Member

Does this need an api change note?

@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Feb 21, 2017

Technically the API doesn't change (you can't rely on indexing the results of get_children() anyways as you can get different number of artists (for a given command) depending on how many bars/errorbars/etc. you draw), and I'd guess most people who were using this API either filtered None out or assumed it would never show up.

@NelleV NelleV merged commit db9e631 into matplotlib:master Feb 22, 2017
@anntzer anntzer deleted the drop-None-container-children branch February 22, 2017 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

X Tutup