Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added get_status() function to the CheckButtons widget #6018

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 4 commits into from
Feb 23, 2016
Merged

Added get_status() function to the CheckButtons widget #6018

merged 4 commits into from
Feb 23, 2016

Conversation

DanHickstein
Copy link
Contributor

This allows the user to query the status of a CheckButtons instance using
check.get_status() as discussed in issue #5930 (comment)

Here is an adaptation of the CheckButtons example to show this functionality:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import CheckButtons

t = np.arange(0.0, 2.0, 0.01)
s0 = np.sin(2*np.pi*t)
s1 = np.sin(4*np.pi*t)
s2 = np.sin(6*np.pi*t)

fig, ax = plt.subplots()
l0, = ax.plot(t, s0, visible=False, lw=2)
l1, = ax.plot(t, s1, lw=2)
l2, = ax.plot(t, s2, lw=2)
plt.subplots_adjust(left=0.2)

rax = plt.axes([0.05, 0.4, 0.1, 0.15])
check = CheckButtons(rax, ('2 Hz', '4 Hz', '6 Hz'), (False, True, True))

def func(label):
    status = check.get_status()

    l0.set_visible(status[0])
    l1.set_visible(status[1])
    l2.set_visible(status[2])

    print status
    plt.draw()

check.on_clicked(func)

plt.show()

I also fixed a typo in the CheckButtons docstring that referred to them as "radio button".

"""
returns a tuple of the status (True/False) of all of the check buttons
"""
return [l1.get_visible() for (l1,l2) in self.lines]
Copy link
Member

Choose a reason for hiding this comment

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

  • space after comma.

@DanHickstein
Copy link
Contributor Author

@QuLogic: sure! Comma added!

@QuLogic QuLogic added this to the 2.1 (next point release) milestone Feb 18, 2016
@WeatherGod
Copy link
Member

Needs unit test, and an update to whats_new.rst.

On Wed, Feb 17, 2016 at 7:44 PM, Danhickstein [email protected]
wrote:

@QuLogic https://github.com/QuLogic: sure! Comma added!


Reply to this email directly or view it on GitHub
#6018 (comment)
.

@tacaswell
Copy link
Member

Please create a new file in the whats_new folder, not editing the main rst file (it helps keep merge confilcts down). The readme in that folder has a template.

@DanHickstein
Copy link
Contributor Author

@tacaswell @WeatherGod, sounds good! I'll get to work on that.

Added a basic unit test for the CheckButtons class to
lib/matplotlib/tests/test_widgets.py

Also, added a description of the new `get_status` function to
`doc/users/whats_new/CheckButtons_widget_get_status.rst`
@DanHickstein
Copy link
Contributor Author

Okay, I added a file to doc/users/whats_new/ describing the new function, and I included a test_CheckButtons() unit test at the end of test_widgets.py. I couldn't see any other test of the CheckButtons, so I tried to test some of the other methods as well.

I couldn't figure out how to use the do_event() function (defined near the top of test_widgets.py) to simulate a user clicking on the check button, although I assume that I should be able to do this.

@DanHickstein
Copy link
Contributor Author

Hmmm, I don't really understand why the TravisCI tests are failing. It seems to have to do with some colorbar plot comparisons. I don't think that I should have caused any problems with these. Should I worry about this?

@WeatherGod
Copy link
Member

No, there was a problem commit that got merged into master last week that caused problems. I closed/reopened your PR to force a re-run of the CI's.

@WeatherGod
Copy link
Member

Note, we haven't figured out how to force Appveyor to redo their runs, so ignore that for now.

@DanHickstein
Copy link
Contributor Author

Thanks!

@DanHickstein
Copy link
Contributor Author

I cleaned up the code to conform to pep8, and now it passes that test.

The Travis Python 2.7 test is still failing. It's one of the font tests, so it seems unrelated to these changes.

@DanHickstein
Copy link
Contributor Author

Oh, it looks like Travis and Appveyor are building just fine now. Anything else that you would like me to add to this PR?

WeatherGod added a commit that referenced this pull request Feb 23, 2016
Added get_status() function to the CheckButtons widget
@WeatherGod WeatherGod merged commit 1ca5977 into matplotlib:master Feb 23, 2016
@WeatherGod
Copy link
Member

Looks fine to me. Could probably spruce up the unit test a bit, but we can leave that as a future task.

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