Skip to content

Port part of errorfill from Tony Yu's mpltools. #1010

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 8 commits into from
Aug 23, 2012

Conversation

dmcdougall
Copy link
Member

Specifically, the function extrema_from_error_input from

https://github.com/tonysyu/mpltools/blob/master/mpltools/special/errorfill.py#L54

is ported to matplotlib.mlab.

Specifically, the function `extrema_from_error_input` from

https://github.com/tonysyu/mpltools/blob/master/mpltools/special/errorfill.py#L54

is ported to matplotlib.mlab.
xmin = x - xerr
xmax = x + xerr
elif len(xerr) == 2:
xmin, xmax = x - xerr[0], x + xerr[1]
Copy link
Member

Choose a reason for hiding this comment

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

What about the undefined case (not a scalar, nor len in [2, n])?

@pelson
Copy link
Member

pelson commented Jul 14, 2012

Coming at this fresh, why is this called offset_line? It doesn't seem to offset anything, nor use lines. Naming functions is always the hardest part, and the best that I could come up with was error_range (which I don't actually find any better ;-) ).

I could see this function being useful for handling numpy arrays, which makes me wonder whether it would be better to put this straight into numpy rather than mlab?

@dmcdougall
Copy link
Member Author

@pelson I have no idea! It seemed natural given the example in the docstring. How about offset_data?

@jdh2358
Copy link
Collaborator

jdh2358 commented Jul 14, 2012

@pelson re numpy vs mlab: if we have something that is useful to people I like to ship it so that our code works across multiple versions of numpy. If numpy wants something from mlab, or someone wants to push to get it into numpy, that's great, but I'd like to have it in several release cycles of numpy before we stop shipping it. We've done this with a ton of mlab functions over the years and it doesn't seem to have caused many problems. This function in particular is mainly a convenience method for fill_between -- I don't see it being generically useful enough to make it into numpy.

o A tuple of length 2. In this case, yerr[0] is the error below *y* and
yerr[1] is error above *y*.

For example:
Copy link
Member

Choose a reason for hiding this comment

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

My memory is a little haze, but if you put a double colon, and then indent the code, you will get a pretty code block if/when rendered with Sphinx.

o A tuple of length 2. In this case, yerr[0] is the error below *y* and
yerr[1] is error above *y*.

.. For example::
Copy link
Member

Choose a reason for hiding this comment

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

remove "For"

Copy link
Member

Choose a reason for hiding this comment

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

And the leading .. ?

Copy link
Member

Choose a reason for hiding this comment

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

I keep getting sphinx syntax mixed up in my head. A directive is made up of a leading double dots, a space and a single word followed by double colons. Any arguments for that directive follow the double colons. "keyword" arguments (if any) are provided on the subsequent indented lines with the name of the keyword surrounded by colons and the value after it (see doc/api/index.rst for an example). Finally, any remaining indented text is treated as-is as a large string block.

It doesn't look like there is an ".. example::" directive, so I would re-write this part of the docstring as:

yerr[1] is error above *y*. For example::

Copy link
Member Author

Choose a reason for hiding this comment

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

@WeatherGod Where do I put the double dots in your example?

I followed the example below (from pyplot.py):

def figlegend(handles, labels, loc, **kwargs):
    """
    Place a legend in the figure.

    *labels*
      a sequence of strings

    *handles*
      a sequence of :class:`~matplotlib.lines.Line2D` or
      :class:`~matplotlib.patches.Patch` instances

    *loc*
      can be a string or an integer specifying the legend
      location

    A :class:`matplotlib.legend.Legend` instance is returned.

    Example::

      figlegend( (line1, line2, line3),
                 ('label1', 'label2', 'label3'),
                 'upper right' )

    .. seealso::

       :func:`~matplotlib.pyplot.legend`

    """
    l = gcf().legend(handles, labels, loc, **kwargs)
    draw_if_interactive()
    return l

I don't have sphinx, and I have no experience with it, so I'm deferring to you guys for epic sphinxage :)

Copy link
Member

Choose a reason for hiding this comment

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

You don't. Whenever you want to display a code block, you use just double-colons and indent the code block. You might also have to have a blank line as well. The word "example" before the double-colons is not special and can be any word. Sometimes, we even just use double colons on a line all by itself.

@pelson
Copy link
Member

pelson commented Aug 19, 2012

Ok, there is no reason for this not to make it into 1.2.x so I have updated the milestone.

@mdboom
Copy link
Member

mdboom commented Aug 23, 2012

@dmcdougall : Do you consider this ready to merge?

@dmcdougall
Copy link
Member Author

@mdboom Sounds good to me. Thanks for the feedback.

mdboom added a commit that referenced this pull request Aug 23, 2012
Port part of errorfill from Tony Yu's mpltools.
@mdboom mdboom merged commit 486a0cd into matplotlib:master Aug 23, 2012
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