Skip to content

Commit 715abbf

Browse files
black formatting
1 parent 153d63d commit 715abbf

File tree

2 files changed

+143
-101
lines changed

2 files changed

+143
-101
lines changed

test/test_cleanfigure.py

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_replaceDataWithNaN():
7373

7474
with plt.rc_context(rc=RC_PARAMS):
7575
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
76-
l, = ax.plot(xData, yData)
76+
(l,) = ax.plot(xData, yData)
7777

7878
cleanfigure._replaceDataWithNan(l, id_replace)
7979

@@ -106,7 +106,7 @@ def test_removeData():
106106

107107
with plt.rc_context(rc=RC_PARAMS):
108108
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
109-
l, = ax.plot(xData, yData)
109+
(l,) = ax.plot(xData, yData)
110110

111111
cleanfigure._removeData(l, id_remove)
112112
newdata = np.stack(l.get_data(), axis=1)
@@ -138,7 +138,7 @@ def test_removeNaNs():
138138

139139
with plt.rc_context(rc=RC_PARAMS):
140140
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
141-
l, = ax.plot(xData, yData)
141+
(l,) = ax.plot(xData, yData)
142142
cleanfigure._replaceDataWithNan(l, id_replace)
143143
cleanfigure._removeData(l, id_remove)
144144
cleanfigure._removeNaNs(l)
@@ -292,7 +292,7 @@ def test_simplifyLine():
292292
# cleanfigure;
293293
# ```
294294
# """
295-
# # TODO: it looks like matlab changes the data to be plotted when using `stairs` command,
295+
# # TODO: it looks like matlab changes the data to be plotted when using `stairs` command,
296296
# # whereas matplotlib stores the same data but displays it as a step.
297297
# x = np.linspace(1, 100, 20)
298298
# y = np.linspace(1, 100, 20)
@@ -492,15 +492,16 @@ def test_hist(self):
492492
def test_plot3d(self):
493493
""" """
494494
from mpl_toolkits.mplot3d import Axes3D
495+
495496
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
496497
z = np.linspace(-2, 2, 100)
497-
r = z**2 + 1
498+
r = z ** 2 + 1
498499
x = r * np.sin(theta)
499500
y = r * np.cos(theta)
500501

501502
with plt.rc_context(rc=RC_PARAMS):
502503
fig = plt.figure()
503-
ax = fig.add_subplot(111, projection='3d')
504+
ax = fig.add_subplot(111, projection="3d")
504505
ax.plot(x, y, z)
505506
ax.set_xlim([-2, 2])
506507
ax.set_ylim([-2, 2])
@@ -525,7 +526,7 @@ def test_scatter3d(self):
525526

526527
with plt.rc_context(rc=RC_PARAMS):
527528
fig = plt.figure()
528-
ax = fig.add_subplot(111, projection='3d')
529+
ax = fig.add_subplot(111, projection="3d")
529530
ax.scatter(x, y, z)
530531
ax.set_xlim([20, 80])
531532
ax.set_ylim([20, 80])
@@ -536,12 +537,13 @@ def test_scatter3d(self):
536537
def test_wireframe3D(self):
537538
""" """
538539
from mpl_toolkits.mplot3d import axes3d
540+
539541
# Grab some test data.
540542
X, Y, Z = axes3d.get_test_data(0.05)
541543

542544
with plt.rc_context(rc=RC_PARAMS):
543545
fig = plt.figure()
544-
ax = fig.add_subplot(111, projection='3d')
546+
ax = fig.add_subplot(111, projection="3d")
545547

546548
# Plot a basic wireframe.
547549
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
@@ -553,25 +555,27 @@ def test_surface3D(self):
553555
from mpl_toolkits.mplot3d import Axes3D
554556
from matplotlib import cm
555557
from matplotlib.ticker import LinearLocator, FormatStrFormatter
558+
556559
# Make data.
557560
X = np.arange(-5, 5, 0.25)
558561
Y = np.arange(-5, 5, 0.25)
559562
X, Y = np.meshgrid(X, Y)
560-
R = np.sqrt(X**2 + Y**2)
563+
R = np.sqrt(X ** 2 + Y ** 2)
561564
Z = np.sin(R)
562565

563566
with plt.rc_context(rc=RC_PARAMS):
564567
fig = plt.figure()
565-
ax = fig.gca(projection='3d')
568+
ax = fig.gca(projection="3d")
566569

567570
# Plot the surface.
568-
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
569-
linewidth=0, antialiased=False)
571+
surf = ax.plot_surface(
572+
X, Y, Z, cmap=cm.coolwarm, linewidth=0, antialiased=False
573+
)
570574

571575
# Customize the z axis.
572576
ax.set_zlim(-1.01, 1.01)
573577
ax.zaxis.set_major_locator(LinearLocator(10))
574-
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
578+
ax.zaxis.set_major_formatter(FormatStrFormatter("%.02f"))
575579

576580
# Add a color bar which maps values to colors.
577581
fig.colorbar(surf, shrink=0.5, aspect=5)
@@ -593,24 +597,23 @@ def test_trisurface3D(Self):
593597
n_angles = 36
594598
# Make radii and angles spaces (radius r=0 omitted to eliminate duplication).
595599
radii = np.linspace(0.125, 1.0, n_radii)
596-
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
600+
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
597601

598602
# Repeat all angles for each radius.
599603
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
600604

601605
# Convert polar (radii, angles) coords to cartesian (x, y) coords.
602606
# (0, 0) is manually added at this stage, so there will be no duplicate
603607
# points in the (x, y) plane.
604-
x = np.append(0, (radii*np.cos(angles)).flatten())
605-
y = np.append(0, (radii*np.sin(angles)).flatten())
608+
x = np.append(0, (radii * np.cos(angles)).flatten())
609+
y = np.append(0, (radii * np.sin(angles)).flatten())
606610

607611
# Compute z to make the pringle surface.
608-
z = np.sin(-x*y)
609-
612+
z = np.sin(-x * y)
610613

611614
with plt.rc_context(rc=RC_PARAMS):
612615
fig = plt.figure()
613-
ax = fig.gca(projection='3d')
616+
ax = fig.gca(projection="3d")
614617

615618
ax.plot_trisurf(x, y, z, linewidth=0.2, antialiased=True)
616619
with pytest.warns(Warning):
@@ -624,13 +627,13 @@ def test_contour3D(self):
624627

625628
with plt.rc_context(rc=RC_PARAMS):
626629
fig = plt.figure()
627-
ax = fig.add_subplot(111, projection='3d')
630+
ax = fig.add_subplot(111, projection="3d")
628631
X, Y, Z = axes3d.get_test_data(0.05)
629632
cset = ax.contour(X, Y, Z, cmap=cm.coolwarm)
630633
ax.clabel(cset, fontsize=9, inline=1)
631634
with pytest.warns(Warning):
632635
cleanfigure.cleanfigure(fig)
633-
636+
634637
def test_polygon3D(self):
635638
""" """
636639
from mpl_toolkits.mplot3d import Axes3D
@@ -639,7 +642,7 @@ def test_polygon3D(self):
639642

640643
with plt.rc_context(rc=RC_PARAMS):
641644
fig = plt.figure()
642-
ax = fig.gca(projection='3d')
645+
ax = fig.gca(projection="3d")
643646

644647
def cc(arg):
645648
"""
@@ -657,16 +660,17 @@ def cc(arg):
657660
ys[0], ys[-1] = 0, 0
658661
verts.append(list(zip(xs, ys)))
659662

660-
poly = PolyCollection(verts, facecolors=[cc('r'), cc('g'), cc('b'),
661-
cc('y')])
663+
poly = PolyCollection(
664+
verts, facecolors=[cc("r"), cc("g"), cc("b"), cc("y")]
665+
)
662666
poly.set_alpha(0.7)
663-
ax.add_collection3d(poly, zs=zs, zdir='y')
667+
ax.add_collection3d(poly, zs=zs, zdir="y")
664668

665-
ax.set_xlabel('X')
669+
ax.set_xlabel("X")
666670
ax.set_xlim3d(0, 10)
667-
ax.set_ylabel('Y')
671+
ax.set_ylabel("Y")
668672
ax.set_ylim3d(-1, 4)
669-
ax.set_zlabel('Z')
673+
ax.set_zlabel("Z")
670674
ax.set_zlim3d(0, 1)
671675
with pytest.warns(Warning):
672676
cleanfigure.cleanfigure(fig)
@@ -677,23 +681,22 @@ def test_bar3D(self):
677681
import matplotlib.pyplot as plt
678682
import numpy as np
679683

680-
681684
with plt.rc_context(rc=RC_PARAMS):
682685
fig = plt.figure()
683-
ax = fig.add_subplot(111, projection='3d')
684-
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
686+
ax = fig.add_subplot(111, projection="3d")
687+
for c, z in zip(["r", "g", "b", "y"], [30, 20, 10, 0]):
685688
xs = np.arange(20)
686689
ys = np.random.rand(20)
687690

688691
# You can provide either a single color or an array. To demonstrate this,
689692
# the first bar of each set will be colored cyan.
690693
cs = [c] * len(xs)
691-
cs[0] = 'c'
692-
ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)
694+
cs[0] = "c"
695+
ax.bar(xs, ys, zs=z, zdir="y", color=cs, alpha=0.8)
693696

694-
ax.set_xlabel('X')
695-
ax.set_ylabel('Y')
696-
ax.set_zlabel('Z')
697+
ax.set_xlabel("X")
698+
ax.set_ylabel("Y")
699+
ax.set_zlabel("Z")
697700
with pytest.warns(Warning):
698701
cleanfigure.cleanfigure(fig)
699702

@@ -703,21 +706,26 @@ def test_quiver3D(self):
703706
import matplotlib.pyplot as plt
704707
import numpy as np
705708

706-
707709
with plt.rc_context(rc=RC_PARAMS):
708710
fig = plt.figure()
709-
ax = fig.gca(projection='3d')
711+
ax = fig.gca(projection="3d")
710712

711713
# Make the grid
712-
x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2),
713-
np.arange(-0.8, 1, 0.2),
714-
np.arange(-0.8, 1, 0.8))
714+
x, y, z = np.meshgrid(
715+
np.arange(-0.8, 1, 0.2),
716+
np.arange(-0.8, 1, 0.2),
717+
np.arange(-0.8, 1, 0.8),
718+
)
715719

716720
# Make the direction data for the arrows
717721
u = np.sin(np.pi * x) * np.cos(np.pi * y) * np.cos(np.pi * z)
718722
v = -np.cos(np.pi * x) * np.sin(np.pi * y) * np.cos(np.pi * z)
719-
w = (np.sqrt(2.0 / 3.0) * np.cos(np.pi * x) * np.cos(np.pi * y) *
720-
np.sin(np.pi * z))
723+
w = (
724+
np.sqrt(2.0 / 3.0)
725+
* np.cos(np.pi * x)
726+
* np.cos(np.pi * y)
727+
* np.sin(np.pi * z)
728+
)
721729

722730
ax.quiver(x, y, z, u, v, w, length=0.1, normalize=True)
723731
with pytest.warns(Warning):
@@ -731,42 +739,43 @@ def test_2D_in_3D(self):
731739

732740
with plt.rc_context(rc=RC_PARAMS):
733741
fig = plt.figure()
734-
ax = fig.gca(projection='3d')
742+
ax = fig.gca(projection="3d")
735743

736744
# Plot a sin curve using the x and y axes.
737745
x = np.linspace(0, 1, 100)
738746
y = np.sin(x * 2 * np.pi) / 2 + 0.5
739-
ax.plot(x, y, zs=0, zdir='z', label='curve in (x,y)')
747+
ax.plot(x, y, zs=0, zdir="z", label="curve in (x,y)")
740748

741749
# Plot scatterplot data (20 2D points per colour) on the x and z axes.
742-
colors = ('r', 'g', 'b', 'k')
743-
x = np.random.sample(20*len(colors))
744-
y = np.random.sample(20*len(colors))
750+
colors = ("r", "g", "b", "k")
751+
x = np.random.sample(20 * len(colors))
752+
y = np.random.sample(20 * len(colors))
745753
c_list = []
746754
for c in colors:
747-
c_list += [c]*20
755+
c_list += [c] * 20
748756
# By using zdir='y', the y value of these points is fixed to the zs value 0
749757
# and the (x,y) points are plotted on the x and z axes.
750-
ax.scatter(x, y, zs=0, zdir='y', c=c_list, label='points in (x,z)')
758+
ax.scatter(x, y, zs=0, zdir="y", c=c_list, label="points in (x,z)")
751759

752760
# Make legend, set axes limits and labels
753761
ax.legend()
754762
ax.set_xlim(0, 1)
755763
ax.set_ylim(0, 1)
756764
ax.set_zlim(0, 1)
757-
ax.set_xlabel('X')
758-
ax.set_ylabel('Y')
759-
ax.set_zlabel('Z')
765+
ax.set_xlabel("X")
766+
ax.set_ylabel("Y")
767+
ax.set_zlabel("Z")
760768

761769
# Customize the view angle so it's easier to see that the scatter points lie
762770
# on the plane y=0
763-
ax.view_init(elev=20., azim=-35)
771+
ax.view_init(elev=20.0, azim=-35)
764772
with pytest.warns(Warning):
765773
cleanfigure.cleanfigure(fig)
766774

767775

768776
class Test_lineplot:
769777
""" """
778+
770779
def test_line_no_markers(self):
771780
"""test high-level usage for simple example.
772781
Test is successfull if generated tikz code saves correct amount of lines
@@ -878,6 +887,7 @@ def test_sine(self):
878887

879888
class Test_subplots:
880889
""" """
890+
881891
def test_subplot(self):
882892
"""octave code
883893

0 commit comments

Comments
 (0)