Skip to content

Commit 0555ef1

Browse files
committed
Fixed some style issues. Added violinplot to boilerplate.py
Added comments for test cases referencing the origins.
1 parent ef89a14 commit 0555ef1

File tree

4 files changed

+130
-79
lines changed

4 files changed

+130
-79
lines changed

boilerplate.py

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def boilerplate_gen():
146146
'tricontourf',
147147
'tripcolor',
148148
'triplot',
149+
'violinplot',
149150
'vlines',
150151
'xcorr',
151152
'barbs',

lib/matplotlib/pyplot.py

+22
Original file line numberDiff line numberDiff line change
@@ -3396,6 +3396,28 @@ def triplot(*args, **kwargs):
33963396

33973397
return ret
33983398

3399+
# This function was autogenerated by boilerplate.py. Do not edit as
3400+
# changes will be lost
3401+
@_autogen_docstring(Axes.violinplot)
3402+
def violinplot(dataset, positions=None, vert=True, widths=0.5, showmeans=False,
3403+
showextrema=True, showmedians=False, points=100, hold=None):
3404+
ax = gca()
3405+
# allow callers to override the hold state by passing hold=True|False
3406+
washold = ax.ishold()
3407+
3408+
if hold is not None:
3409+
ax.hold(hold)
3410+
try:
3411+
ret = ax.violinplot(dataset, positions=positions, vert=vert,
3412+
widths=widths, showmeans=showmeans,
3413+
showextrema=showextrema, showmedians=showmedians,
3414+
points=points)
3415+
draw_if_interactive()
3416+
finally:
3417+
ax.hold(washold)
3418+
3419+
return ret
3420+
33993421
# This function was autogenerated by boilerplate.py. Do not edit as
34003422
# changes will be lost
34013423
@_autogen_docstring(Axes.vlines)

lib/matplotlib/tests/test_axes.py

+98-71
Original file line numberDiff line numberDiff line change
@@ -1564,149 +1564,176 @@ def test_boxplot_bad_ci_2():
15641564
fig, ax = plt.subplots()
15651565
assert_raises(ValueError, ax.boxplot, [x, x],
15661566
conf_intervals=[[1, 2], [1]])
1567+
1568+
15671569
# violin plot data initialization
15681570
ax = plt.axes()
1569-
data = [([ 0.07902449, -0.16769639, 1.1572525 , 0.71400729, -0.17916727,
1570-
-1.15346725, -0.5298936 , 1.16570619, 1.13612837, -0.66830221,
1571-
-0.76738509, 0.85911678, 0.56446469, 0.64772651, -1.97432723,
1572-
-1.11794413, 0.4094635 , 2.52767469, -0.81092698, -0.23422668,
1573-
0.423861 , 0.01702886, -0.58954823, -1.05303546, 0.22632754,
1574-
-1.88620214, 0.06759594, -0.51663253, -0.38821442, -0.5462294 ,
1575-
-0.39967334, -1.2690421 , -0.271953 , 0.19494831, 1.0674446 ,
1576-
0.06632929, 0.9051155 , -0.06507299, -0.58885588, 0.03405925,
1577-
0.60666877, -0.25755542, 1.06387913, -0.50576651, -0.51104135,
1578-
-0.65366091, -1.10801137, 0.55746182, 0.27206281, 0.25658797,
1579-
0.008253 , -0.07254077, -0.77980703, -1.5707303 , -0.74731452,
1580-
-0.38364682, 1.37653142, -0.04123221, -0.84737153, 0.26552353,
1581-
0.80039697, 0.17446856, 0.32860543, 0.79574814, -1.88942134]),
1582-
([ 3.99586977e-01, 1.09626020e+00, 2.64974356e-01,5.49065532e-01,
1583-
-1.86679220e+00, -4.23951661e-01, -3.66858136e-01,7.39441772e-02,
1584-
-1.25772592e+00, -1.14864510e+00, -7.59625813e-01,-2.67830782e-01,
1585-
-2.68205909e-01, -2.64119550e-02, -3.00092210e-01,-1.17080290e-03,
1586-
1.25324397e+00, 1.97518726e-01, 9.74395138e-01, -2.52217468e-01,
1587-
-2.00424239e+00, -2.20525681e+00, 6.32069078e-01, -5.59674009e-02,
1588-
-1.13007054e+00, 8.47680697e-01, -1.41563783e+00, 6.84885681e-02,
1589-
8.06629024e-01, 1.06561293e+00, 1.48755064e-01, 1.06241336e+00,
1590-
-1.53742677e+00, -9.40116707e-01, -2.35342351e-01, 4.07790960e-01,
1591-
9.59066810e-01, 1.83262266e+00, -1.44675794e-01, -1.61663789e+00,
1592-
-3.34055942e-01, -1.65081542e+00, 6.54573563e-01, -4.80998938e-01,
1593-
-4.77104620e-01, 4.35836897e-01, 1.54488583e-01, 1.90264111e+00,
1594-
-1.73584727e+00, 2.84097580e-01, -6.67013428e-01, -5.47647643e-01,
1595-
-1.77584471e-01, -6.54191064e-01, 1.02366976e+00, 1.57777769e+00,
1596-
2.10098337e-01, -5.34631915e-02, 4.28913084e-01, -5.56544884e-02,
1597-
1.64250239e-01, -4.77299164e-01, -8.40402132e-01, -1.58474541e-01]),
1598-
([-0.00975961, -0.9572654 , -0.02331628, -0.88758431, 0.36594918,
1599-
0.58733922, 0.12169127, -0.17451044, -1.48322656, -0.64203124,
1600-
1.01373274, -0.77332978, -1.64093613, 0.07944897, 1.79420792,
1601-
-0.95589844, -2.19618124, 0.99478738, -1.98933911, 0.21046525,
1602-
-2.31831045, 1.11045528, -0.51981581, 0.49740564, -0.40365721,
1603-
-0.30515722, -0.60601737, -1.05976064, 1.43356283, -0.59014164,
1604-
0.58822025, 1.80100922, -1.40905671, 0.74553523, -1.57655404,
1605-
0.29342432, 0.35548625, -0.99138976, -1.37339981, 0.63871936,
1606-
-0.60010678, -0.73597695, -0.12228469, 0.2467333 , 0.03750118,
1607-
-0.45755544, -0.8648646 , 0.13883081, -0.11239293, -0.7661388 ,
1608-
-0.70841112, -0.51668825, 2.2590876 , 0.61731299, -0.33742898,
1609-
1.40708783, -1.43371511, -1.20425544, 0.79551956, -0.38148021,
1610-
-0.05703633, -0.42718744, 1.86441201, -0.36006341, -2.23769144]),
1611-
([ 0.28379466, 0.31202331, 0.54110464, 0.79957469, 0.02825945,
1612-
1.39430266, 0.38945253, 0.25840893, -1.03405387, 0.3951418 ,
1613-
-0.32782812, -0.49764761, 1.67314785, 0.57207158, 0.42868172,
1614-
-0.66405633, 0.49477738, -0.24707622, -0.91179434, -0.88450974,
1615-
1.47387423, 1.27147423, -1.28664994, 0.84428091, 0.19419244,
1616-
-1.27527008, 1.44462176, 1.21255381, 1.74448494, -1.47661372,
1617-
-1.00577117, -0.68746569, -0.85283125, -0.87339905, -0.05053922,
1618-
1.79110014, -0.99663248, 0.52435397, 1.17699107, -1.51437376,
1619-
0.52402067, -0.68885234, 1.84101899, 1.09318846, 0.66686321,
1620-
-1.14796045, 0.54247117, -2.21273401, -0.44526518, 1.08591603,
1621-
-1.86173825, -1.31016714, 0.7782744 , 0.76330906, -0.96452241,
1622-
-1.34983597, -0.90317774, 0.20187156, -2.03515866, 1.35603702,
1623-
1.01390851, 0.29328188, -0.2223719 , -1.29928072, 0.59399753])]
1571+
data = [([+0.07902449, -0.16769639, +1.1572525, +0.71400729, -0.17916727,
1572+
-1.15346725, -0.5298936, +1.16570619, +1.13612837, -0.66830221,
1573+
-0.76738509, +0.85911678, +0.56446469, +0.64772651, -1.97432723,
1574+
-1.11794413, +0.4094635, +2.52767469, -0.81092698, -0.23422668,
1575+
+0.423861, +0.01702886, -0.58954823, -1.05303546, +0.22632754,
1576+
-1.88620214, +0.06759594, -0.51663253, -0.38821442, -0.5462294,
1577+
-0.39967334, -1.2690421, -0.271953, +0.19494831, +1.0674446,
1578+
+0.06632929, +0.9051155, -0.06507299, -0.58885588, +0.03405925,
1579+
+0.60666877, -0.25755542, +1.06387913, -0.50576651, -0.51104135,
1580+
-0.65366091, -1.10801137, +0.55746182, +0.27206281, +0.25658797,
1581+
+0.008253, -0.07254077, -0.77980703, -1.5707303, -0.74731452,
1582+
-0.38364682, +1.37653142, -0.04123221, -0.84737153, +0.26552353,
1583+
+0.80039697, +0.17446856, +0.32860543, +0.79574814, -1.88942134]),
1584+
([+3.99586977e-01, +1.09626020e+00, +2.64974356e-01, +5.49065532e-01,
1585+
-1.86679220e+00, -4.23951661e-01, -3.66858136e-01, +7.39441772e-02,
1586+
-1.25772592e+00, -1.14864510e+00, -7.59625813e-01, -2.67830782e-01,
1587+
-2.68205909e-01, -2.64119550e-02, -3.00092210e-01, -1.17080290e-03,
1588+
+1.25324397e+00, +1.97518726e-01, +9.74395138e-01, -2.52217468e-01,
1589+
-2.00424239e+00, -2.20525681e+00, +6.32069078e-01, -5.59674009e-02,
1590+
-1.13007054e+00, +8.47680697e-01, -1.41563783e+00, +6.84885681e-02,
1591+
+8.06629024e-01, +1.06561293e+00, +1.48755064e-01, +1.06241336e+00,
1592+
-1.53742677e+00, -9.40116707e-01, -2.35342351e-01, +4.07790960e-01,
1593+
+9.59066810e-01, +1.83262266e+00, -1.44675794e-01, -1.61663789e+00,
1594+
-3.34055942e-01, -1.65081542e+00, +6.54573563e-01, -4.80998938e-01,
1595+
-4.77104620e-01, +4.35836897e-01, +1.54488583e-01, +1.90264111e+00,
1596+
-1.73584727e+00, +2.84097580e-01, -6.67013428e-01, -5.47647643e-01,
1597+
-1.77584471e-01, -6.54191064e-01, +1.02366976e+00, +1.57777769e+00,
1598+
+2.10098337e-01, -5.34631915e-02, +4.28913084e-01, -5.56544884e-02,
1599+
+1.64250239e-01, -4.77299164e-01, -8.40402132e-01, -1.58474541e-01]),
1600+
([-0.00975961, -0.9572654, -0.02331628, -0.88758431, +0.36594918,
1601+
+0.58733922, +0.12169127, -0.17451044, -1.48322656, -0.64203124,
1602+
+1.01373274, -0.77332978, -1.64093613, +0.07944897, +1.79420792,
1603+
-0.95589844, -2.19618124, +0.99478738, -1.98933911, +0.21046525,
1604+
-2.31831045, +1.11045528, -0.51981581, +0.49740564, -0.40365721,
1605+
-0.30515722, -0.60601737, -1.05976064, +1.43356283, -0.59014164,
1606+
+0.58822025, +1.80100922, -1.40905671, +0.74553523, -1.57655404,
1607+
+0.29342432, +0.35548625, -0.99138976, -1.37339981, +0.63871936,
1608+
-0.60010678, -0.73597695, -0.12228469, +0.2467333, +0.03750118,
1609+
-0.45755544, -0.8648646, +0.13883081, -0.11239293, -0.7661388,
1610+
-0.70841112, -0.51668825, +2.2590876, +0.61731299, -0.33742898,
1611+
+1.40708783, -1.43371511, -1.20425544, +0.79551956, -0.38148021,
1612+
-0.05703633, -0.42718744, +1.86441201, -0.36006341, -2.23769144]),
1613+
([+0.28379466, +0.31202331, +0.54110464, +0.79957469, +0.02825945,
1614+
+1.39430266, +0.38945253, +0.25840893, -1.03405387, +0.3951418,
1615+
-0.32782812, -0.49764761, +1.67314785, +0.57207158, +0.42868172,
1616+
-0.66405633, +0.49477738, -0.24707622, -0.91179434, -0.88450974,
1617+
+1.47387423, +1.27147423, -1.28664994, +0.84428091, +0.19419244,
1618+
-1.27527008, +1.44462176, +1.21255381, +1.74448494, -1.47661372,
1619+
-1.00577117, -0.68746569, -0.85283125, -0.87339905, -0.05053922,
1620+
+1.79110014, -0.99663248, +0.52435397, +1.17699107, -1.51437376,
1621+
+0.52402067, -0.68885234, +1.84101899, +1.09318846, +0.66686321,
1622+
-1.14796045, +0.54247117, -2.21273401, -0.44526518, +1.08591603,
1623+
-1.86173825, -1.31016714, +0.7782744, +0.76330906, -0.96452241,
1624+
-1.34983597, -0.90317774, +0.20187156, -2.03515866, +1.35603702,
1625+
+1.01390851, +0.29328188, -0.2223719, -1.29928072, +0.59399753])]
1626+
16241627

16251628
# violin plot test starts here
16261629
@image_comparison(baseline_images=['test_vert_violinplot_baseline'])
16271630
def test_vert_violinplot_baseline():
16281631
ax = plt.axes()
1629-
ax.violinplot(data,range(4),showmeans=0,showextrema=0,showmedians=0)
1632+
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=0,
1633+
showmedians=0)
1634+
16301635

16311636
@image_comparison(baseline_images=['test_vert_violinplot_showmeans'])
16321637
def test_vert_violinplot_showmeans():
16331638
ax = plt.axes()
1634-
ax.violinplot(data,range(4),showmeans=1,showextrema=0,showmedians=0)
1639+
ax.violinplot(data, positions=range(4), showmeans=1, showextrema=0,
1640+
showmedians=0)
1641+
16351642

16361643
@image_comparison(baseline_images=['test_vert_violinplot_showextrema'])
16371644
def test_vert_violinplot_showextrema():
16381645
ax = plt.axes()
1639-
ax.violinplot(data,range(4),showmeans=0,showextrema=1,showmedians=0)
1646+
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=1,
1647+
showmedians=0)
1648+
16401649

16411650
@image_comparison(baseline_images=['test_vert_violinplot_showmedians'])
16421651
def test_vert_violinplot_showmedians():
16431652
ax = plt.axes()
1644-
ax.violinplot(data,range(4),showmeans=0,showextrema=0,showmedians=1)
1653+
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=0,
1654+
showmedians=1)
1655+
16451656

16461657
@image_comparison(baseline_images=['test_vert_violinplot_showall'])
16471658
def test_vert_violinplot_showall():
16481659
ax = plt.axes()
1649-
ax.violinplot(data,range(4),showmeans=1,showextrema=1,showmedians=1)
1660+
ax.violinplot(data, positions=range(4), showmeans=1, showextrema=1,
1661+
showmedians=1)
16501662

16511663

16521664
@image_comparison(baseline_images=['test_vert_violinplot_custompoints_10'])
16531665
def test_vert_violinplot_custompoints_10():
16541666
ax = plt.axes()
1655-
ax.violinplot(data,range(4),showmeans=0,showextrema=0,showmedians=0,points=10)
1667+
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=0,
1668+
showmedians=0, points=10)
16561669

16571670

16581671
@image_comparison(baseline_images=['test_vert_violinplot_custompoints_200'])
16591672
def test_vert_violinplot_custompoints_200():
16601673
ax = plt.axes()
1661-
ax.violinplot(data,range(4),showmeans=0,showextrema=0,showmedians=0,points=200)
1674+
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=0,
1675+
showmedians=0, points=200)
1676+
16621677

16631678
@image_comparison(baseline_images=['test_horiz_violinplot_baseline'])
16641679
def test_horiz_violinplot_baseline():
16651680
ax = plt.axes()
1666-
ax.violinplot(data,range(4),0,showmeans=0,showextrema=0,showmedians=0)
1681+
ax.violinplot(data, positions=range(4), vert=False, showmeans=0,
1682+
showextrema=0, showmedians=0)
1683+
16671684

16681685
@image_comparison(baseline_images=['test_horiz_violinplot_showmedians'])
16691686
def test_horiz_violinplot_showmedians():
16701687
ax = plt.axes()
1671-
ax.violinplot(data,range(4),0,showmeans=0,showextrema=0,showmedians=1)
1688+
ax.violinplot(data, positions=range(4), vert=False, showmeans=0,
1689+
showextrema=0, showmedians=1)
1690+
16721691

16731692
@image_comparison(baseline_images=['test_horiz_violinplot_showmeans'])
16741693
def test_horiz_violinplot_showmeans():
16751694
ax = plt.axes()
1676-
ax.violinplot(data,range(4),0,showmeans=1,showextrema=0,showmedians=0)
1695+
ax.violinplot(data, positions=range(4), vert=False, showmeans=1,
1696+
showextrema=0, showmedians=0)
1697+
16771698

16781699
@image_comparison(baseline_images=['test_horiz_violinplot_showextrema'])
16791700
def test_horiz_violinplot_showextrema():
16801701
ax = plt.axes()
1681-
ax.violinplot(data,range(4),0,showmeans=0,showextrema=1,showmedians=0)
1702+
ax.violinplot(data, positions=range(4), vert=False, showmeans=0,
1703+
showextrema=1, showmedians=0)
16821704

16831705

16841706
@image_comparison(baseline_images=['test_horiz_violinplot_showall'])
16851707
def test_horiz_violinplot_showall():
16861708
ax = plt.axes()
1687-
ax.violinplot(data,range(4),0,showmeans=1,showextrema=1,showmedians=1)
1709+
ax.violinplot(data, positions=range(4), vert=False, showmeans=1,
1710+
showextrema=1, showmedians=1)
16881711

16891712

16901713
@image_comparison(baseline_images=['test_horiz_violinplot_custompoints_10'])
16911714
def test_horiz_violinplot_custompoints_10():
16921715
ax = plt.axes()
1693-
ax.violinplot(data,range(4),0,showmeans=0,showextrema=0,showmedians=0,points=10)
1716+
ax.violinplot(data, positions=range(4), vert=False, showmeans=0,
1717+
showextrema=0, showmedians=0, points=10)
16941718

16951719

16961720
@image_comparison(baseline_images=['test_horiz_violinplot_custompoints_200'])
16971721
def test_horiz_violinplot_custompoints_200():
16981722
ax = plt.axes()
1699-
ax.violinplot(data,range(4),0,showmeans=0,showextrema=0,showmedians=0,points=200)
1723+
ax.violinplot(data, positions=range(4), vert=False, showmeans=0,
1724+
showextrema=0, showmedians=0, points=200)
1725+
17001726

17011727
# test error
17021728
def test_violinplot_bad_positions():
17031729
ax = plt.axes()
17041730
assert_raises(ValueError, ax.violinplot, data, positions=range(5))
17051731

1732+
17061733
def test_violinplot_bad_widths():
17071734
ax = plt.axes()
1708-
assert_raises(ValueError, ax.violinplot, data,
1709-
positions=range(4), widths=[1,2,3])
1735+
assert_raises(ValueError, ax.violinplot, data, positions=range(4),
1736+
widths=[1, 2, 3])
17101737

17111738
# violin plot test ends here
17121739

lib/matplotlib/tests/test_mlab.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -2758,25 +2758,28 @@ def get_z(x, y):
27582758
np.ma.getmask(correct_zi_masked))
27592759

27602760
#*****************************************************************
2761+
# These Tests where taken from SCIPY with some minor modifications
2762+
# this can be retreived from:
2763+
# https://github.com/scipy/scipy/blob/master/scipy/stats/tests/test_kdeoth.py
27612764
#*****************************************************************
27622765

2763-
27642766
class ksdensity_test():
2765-
27662767

27672768
def test_kde_integer_input(self):
27682769
"""Regression test for #1181."""
27692770
x1 = np.arange(5)
27702771
kde = mlab.GaussianKDE(x1)
2771-
y_expected = [0.13480721, 0.18222869, 0.19514935, 0.18222869, 0.13480721]
2772+
y_expected = [0.13480721, 0.18222869, 0.19514935, 0.18222869,
2773+
0.13480721]
27722774
assert_array_almost_equal(kde(x1), y_expected, decimal=6)
2773-
2775+
27742776
def test_gaussian_kde_covariance_caching(self):
27752777
x1 = np.array([-7, -5, 1, 4, 5], dtype=np.float)
27762778
xs = np.linspace(-10, 10, num=5)
27772779
# These expected values are from scipy 0.10, before some changes to
27782780
# gaussian_kde. They were not compared with any external reference.
2779-
y_expected = [0.02463386, 0.04689208, 0.05395444, 0.05337754, 0.01664475]
2781+
y_expected = [0.02463386, 0.04689208, 0.05395444, 0.05337754,
2782+
0.01664475]
27802783

27812784
# set it to the default bandwidth.
27822785
kde2 = mlab.GaussianKDE(x1, 'scott')
@@ -2797,19 +2800,17 @@ def test_kde_bandwidth_method(self):
27972800
# Supply a scalar
27982801
gkde3 = mlab.GaussianKDE(xn, bw_method=gkde.factor)
27992802

2800-
xs = np.linspace(-7,7,51)
2803+
xs = np.linspace(-7, 7, 51)
28012804
kdepdf = gkde.evaluate(xs)
28022805
kdepdf2 = gkde2.evaluate(xs)
28032806
assert_almost_equal(kdepdf.all(), kdepdf2.all())
28042807
kdepdf3 = gkde3.evaluate(xs)
28052808
assert_almost_equal(kdepdf.all(), kdepdf3.all())
28062809

28072810

2808-
28092811
#*****************************************************************
28102812
#*****************************************************************
28112813

2812-
28132814
if __name__ == '__main__':
28142815
import nose
28152816
import sys

0 commit comments

Comments
 (0)