Skip to content

Added support for displaying percentiles to violinplot function #9971

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

Conversation

Dylan-Dotti
Copy link

PR Summary

These changes will add the option for displaying percentile lines in the violinplot function. For each list given as input (2D for more than one plot), the respective plots will display lines at the percentiles given by that list.
I also wanted to mention KurtWink, my collaborator for this project. We needed to remake the repository we were using to set it up for a PR (a bit new to GitHub), and I ended up pushing all our final changes at once.
https://github.com//issues/8532

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@dstansby
Copy link
Member

Looks like a cool new feature! Could you post a short example of how this works in practice?

@jklymak
Copy link
Member

jklymak commented Dec 11, 2017

Yes, and it needs a test...

@Dylan-Dotti
Copy link
Author

Here's the code I've been using to test my changes, though it only covers the case of all plots having the same percentiles.

import matplotlib.pyplot as plt
import numpy as np

np.random.seed(19680800)
fs = 10
pos = [3, 4, 5]
data = []
percentiles = []
for std in pos:
    data.append(np.random.normal(0, std, size=100))
    percentiles.append([5.0, 20.0, 80.0, 95.0]) 

plt.violinplot(data, pos, points=20, widths=0.3, showmeans=True, 
               showextrema=True, showmedians=True, percentiles=percentiles)
plt.title('Custom violinplot 1', fontsize=fs)
plt.show()

Using something like

percentiles=[[],[5.0, 95.0],[20.0, 80.0]]

Will display different percentiles for each plot (or none in the case of empty list).

I will try to write tests after my finals, though I'm not quite sure how to go about it yet.

@jklymak
Copy link
Member

jklymak commented Dec 11, 2017

Thats great! Let us know if you need pointers...

http://matplotlib.org/devel/testing.html

@tacaswell tacaswell added this to the v2.2 milestone Dec 13, 2017
@Dylan-Dotti
Copy link
Author

Dylan-Dotti commented Dec 17, 2017

When I was trying to run 'python tests.py' after building from the Linux guide here I got this error:

dylan@dylan-VirtualBox:~/violinfeaturebranch/matplotlib$ sudo python tests.py
('Python byte-compilation optimization level:', 0)
/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py:1474: UserWarning: Matplotlib is 
not built with the correct FreeType version to run tests.  Set local_freetype=True in setup.cfg 
and rebuild. Expect many image comparison failures below. Expected freetype version 2.6.1. 
Found freetype version 2.6.1. Freetype build type is not local
  "" if ft2font.__freetype_build_type__ == 'local' else "not "
Traceback (most recent call last):
  File "tests.py", line 56, in <module>
    recursionlimit=args.recursionlimit)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1494, in test
    raise ImportError("Matplotlib test data is not installed")
ImportError: Matplotlib test data is not installed

I changed 'local_freetype' to True in setup.cfg.template and rebuilt, but this did not fix it.
I then tried following the instructions for installing in dev mode here. I edited setup.cfg.template to set 'tests' to True as well. I also edited ci/travis/setup.cfg (I think this is the right file?) to look like the 3 line file shown in the guide and rebuilt again.

When trying again, I got the same error, but this time many tests ran with the results:

============== 9 skipped, 3 xfailed, 6965 error in 16.51 seconds ===============

All the errors I saw looked like this:

/home/dylan/violinfeaturebranch/matplotlib/lib/matplotlib/testing/conftest.py:19
__________________ ERROR at setup of test_outward_ticks[png] ___________________
pytest.fixture functions cannot use ``yield``. Instead write and return an inner function/generator 
and let the consumer call and iterate over it.:

I'm using a relatively fresh VirtualBox VM running Ubuntu 16.04

@jklymak
Copy link
Member

jklymak commented Dec 17, 2017

https://matplotlib.org/devel/testing.html I would guess your pytest is too old..

@anntzer
Copy link
Contributor

anntzer commented Dec 17, 2017

We don't actually support pytest 3.0 (xref #9317).

@jklymak
Copy link
Member

jklymak commented May 28, 2018

@Dylan-Dotti are you still interested in this? We'd love to see it pushed through...

If you really have trouble setting up the testing environment, its not considered too bad to just let our CI process handle the tests...

@jklymak jklymak modified the milestones: needs sorting, v3.0 May 28, 2018
@jklymak jklymak modified the milestones: v3.0, needs sorting Jul 9, 2018
@timhoffm
Copy link
Member

Superseeded by #14107.

@timhoffm timhoffm closed this May 12, 2019
@QuLogic QuLogic modified the milestones: needs sorting, unassigned May 13, 2019
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.

7 participants