8000 adding keyword plotting by choldgraf · Pull Request #8566 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

adding keyword plotting #8566

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

Merged
merged 3 commits into from
May 5, 2017
Merged

Conversation

choldgraf
Copy link
Contributor

Two short little snippets of code to demo plotting with keywords. In this case I'm using a dictionary but mention that you could use a DataFrame if you wanted. Mentioned in #8555

@choldgraf choldgraf mentioned this pull request May 4, 2017
11 tasks
======================

There are some instances where you have data in a format that lets you
access particular variables with strings. For example, with a ``recarray``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@choldgraf choldgraf force-pushed the adding_data_kwarg branch from fd1ef5d to 0ed3497 Compare May 4, 2017 05:54
@choldgraf
Copy link
Contributor Author

that's a good point @anntzer - I actually noticed that it didn't seem like matplotlib had intersphinx activated. Any particular reason for that? Latest push activates the intersphinx extension and adds in some common packages. Also fixes the rst

@choldgraf choldgraf force-pushed the adding_data_kwarg branch from 0ed3497 to b97d6ec Compare May 4, 2017 05:58
@anntzer
Copy link
Contributor
anntzer commented May 4, 2017

Probably because matplotlib's sphinx setup may predate intersphinx? (it is certainly based on a very old version of sphinx).

@choldgraf
Copy link
Contributor Author

Probably because matplotlib's sphinx setup may predate intersphinx?

Not anymore! ;-)

doc/conf.py Outdated
@@ -88,6 +88,13 @@ def _check_deps():

autodoc_docstring_signature = True

intersphinx_mapping = {
'python': ('http://docs.python.org/', None),
'numpy': ('http://docs.scipy.org/doc/numpy-dev/', None),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should link to the stable version of numpy docs (https://docs.scipy.org/doc/numpy/)

doc/conf.py Outdated
intersphinx_mapping = {
'python': ('http://docs.python.org/', None),
'numpy': ('http://docs.scipy.org/doc/numpy-dev/', None),
'scipy': ('http://scipy.github.io/devdocs/', None),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this should be the stable version of the docs (https://docs.scipy.org/doc/scipy/reference/)

@@ -0,0 +1,24 @@
"""
Plotting with keywords
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a line of = signs above the title too I think

np.random.seed(19680801)

data = dict([(label, np.random.randn(50)) for label in ['a', 'b', 'c', 'd']])
data['d'] = np.abs(data['d']) * 100
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, as much as it's more work in some ways, I feel like an example with a clear structure, so something like:

data = { 'a' : [1,2,3,4,5,5,6,7],
              'b' :[4,5, 6,2,3, 4, 5],
              'c': [3,1,2,3,4,5,6,3],
              'd':[1,2,3,4,5,6,7,8]}

might work better since the point of this is to really clearly see what the kwarg does.

# the ``data`` keyword argument. If provided, then you may generate plots with
# the strings corresponding to these variables.

data = dict([(label, np.random.randn(50)) for label in ['a', 'b', 'c']])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@dstansby dstansby added this to the 2.1 (next point release) milestone May 4, 2017
@choldgraf choldgraf force-pushed the adding_data_kwarg branch from b97d6ec to 512b4eb Compare May 5, 2017 01:09
@choldgraf
Copy link
Contributor Author

comments addressed!

@choldgraf
Copy link
Contributor Author

ah I see - you mean using dict() vs {} yeah? I default to dict() because I think it's the most generally supported in earlier versions of python (maybe <2.7?) so I just default to it. If it's a problem I can use the curly brackets...

Copy link
Member
@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dstansby dstansby changed the title adding keyword plotting [MRG+1] adding keyword plotting May 5, 2017
doc/conf.py Outdated
@@ -88,6 +88,13 @@ def _check_deps():

autodoc_docstring_signature = True

intersphinx_mapping = {
'python': ('http://docs.python.org/', None),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https also; would be nice if this intersphinx change were a separate commit.

@choldgraf choldgraf force-pushed the adding_data_kwarg branch from 512b4eb to c3f5715 Compare May 5, 2017 02:50
@choldgraf
Copy link
Contributor Author

latest version has curly brackets + https + intersphinx in a diff commit

Copy link
Member
@story645 story645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting up w/ my nitpicking. Same down here please.

@choldgraf
Copy link
Contributor Author
choldgraf commented May 5, 2017

Same down here please

down where? @story645

# the ``data`` keyword argument. If provided, then you may generate plots with
# the strings corresponding to these variables.

data = dict([('a', np.arange(50)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Down here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops - this is how you know I should probably stop coding for the day ;-)

@choldgraf choldgraf force-pushed the adding_data_kwarg branch from 12b80fe to a24ca89 Compare May 5, 2017 03:17
doc/conf.py Outdated
'python': ('https://docs.python.org/', None),
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None),
'pandas': ('https://pandas.pydata.org/pandas-docs/stable', None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's not accessible over https, unfortunately. Also, why two-space indent?


fig, ax = plt.subplots()
ax.scatter('a', 'b', c='c', s='d', data=data)
ax.set(xlabel='a', ylabel='b')
Copy link
Member

Choose a reason for hiding this comment

The reas F438 on will be displayed to describe this comment to others. Learn more.

Just to be clear, this doesn't try to somehow pull something out of data; maybe use something like 'Entry a'/'Column a' or similar to avoid implying that.

:class:`numpy.recarray` or :class:`pandas.DataFrame`.

Matplotlib allows you provide such an object with
the ``data`` keyword argument. If provided, then you may generate plots with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly over-eager wrapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you mean? Doesn't this need to be double ticks since it's rST?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the line above this is wrapped at like 50 chars instead of 79.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh - ok I removed the extra whitespace. is that such a big deal? I prefer to have extra whitespace as it makes it easier to reword etc without having to bump everything down a bunch of lines

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's not major, but I just think it looks odd when one line is broken much earlier than the rest; it didn't even break at the end of a sentence.

@choldgraf choldgraf force-pushed the adding_data_kwarg branch from a24ca89 to 2e9a8c2 Compare May 5, 2017 04:35
@choldgraf
Copy link
Contributor Author

ok comments addressed

@story645
Copy link
Member
story645 commented May 5, 2017

Sorry, clicked on wrong thing and thought you hadn't changed both examples.

@choldgraf choldgraf force-pushed the adding_data_kwarg branch from 2e9a8c2 to 4de797f Compare May 5, 2017 04:37
@choldgraf
Copy link
Contributor Author
choldgraf commented May 5, 2017

Sorry, clicked on wrong thing and thought you hadn't changed both examples

no you were right - I had missed the tutorial!

@QuLogic
Copy link
Member
QuLogic commented May 5, 2017

There seems to be some problems building the docs, but I'm not sure if it's this change or some external problem.

@choldgraf choldgraf force-pushed the adding_data_kwarg branch from 4de797f to 57aa332 Compare May 5, 2017 20:12
@choldgraf
Copy link
Contributor Author

I think it's because the tutorial was using plt.plot and was getting the s kwarg which isn't valid for plot. Latest commit uses scatter which is what I was going for anyway.

@choldgraf choldgraf force-pushed the adding_data_kwarg branch from 57aa332 to b7e31f3 Compare May 5, 2017 21:06
@dstansby
Copy link
Member
dstansby commented May 5, 2017

Seems to be all working now!

@dstansby dstansby merged commit e232afe into matplotlib:master May 5, 2017
@dstansby dstansby changed the title [MRG+1] adding keyword plotting adding keyword plotting May 5, 2017
@choldgraf
Copy link
Contributor Author

🍻

@QuLogic
Copy link
Member
QuLogic commented May 7, 2017

BTW, wherever you originally wrote the commit and where you updated it seem to disagree on your name/email.

@choldgraf
Copy link
Contributor Author

ah that's annoying - I made a commit from my lab computer, must have been set up w a different address. thanks for noticing

@@ -19,7 +19,7 @@ body {
}

a {
color: #CA7900;
color: #CA7900 !important;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make this change? Links no longer change colour on hover.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason for this was to make the inline links show up within sphinx-gallery pages (they weren't showing up before). I didn't realize this was going to mess up the other links as well. A better way for me to have done this would be to add a new rule instead:

div.highlight-python a {
    color: #CA7900 !important;
}

want me to add this commit to the toolkits PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed in the toolkit PR, works fine now and should be merged soon! Good find

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that require a :hover rule as well?

Copy link
Contributor Author
@choldgraf choldgraf May 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep there's a new hover in there too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0