Skip to content

Commit 1308d8c

Browse files
committed
new black
1 parent a8b1e69 commit 1308d8c

File tree

14 files changed

+86
-104
lines changed

14 files changed

+86
-104
lines changed

test/helpers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010

1111
def print_tree(obj, indent=""):
12-
"""Recursively prints the tree structure of the matplotlib object.
13-
"""
12+
"""Recursively prints the tree structure of the matplotlib object."""
1413
if isinstance(obj, matplotlib.text.Text):
1514
print(indent, type(obj).__name__, f'("{obj.get_text()}")')
1615
else:

test/test_hatch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
def plot():
55
"""
6-
Hatch demo code from
7-
https://matplotlib.org/3.1.1/gallery/shapes_and_collections/hatch_demo.html
6+
Hatch demo code from
7+
https://matplotlib.org/3.1.1/gallery/shapes_and_collections/hatch_demo.html
88
9-
Slightly modified to test more aspects of the hatch implementation
9+
Slightly modified to test more aspects of the hatch implementation
1010
"""
1111
import matplotlib.pyplot as plt
1212
from matplotlib.patches import Ellipse, Polygon

tikzplotlib/_axes.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ def _common_texification(string):
1414

1515
class Axes:
1616
def __init__(self, data, obj): # noqa: C901
17-
"""Returns the PGFPlots code for an axis environment.
18-
"""
17+
"""Returns the PGFPlots code for an axis environment."""
1918
self.content = []
2019

2120
# Are we dealing with an axis that hosts a colorbar? Skip then, those are
@@ -270,14 +269,14 @@ def _ticks(self, data, obj):
270269
self.axis_options.append("tick align=center")
271270

272271
# Set each rotation for every label
273-
x_tick_rotation_and_horizontal_alignment = self._get_label_rotation_and_horizontal_alignment(
274-
obj, data, "x"
272+
x_tick_rotation_and_horizontal_alignment = (
273+
self._get_label_rotation_and_horizontal_alignment(obj, data, "x")
275274
)
276275
if x_tick_rotation_and_horizontal_alignment:
277276
self.axis_options.append(x_tick_rotation_and_horizontal_alignment)
278277

279-
y_tick_rotation_and_horizontal_alignment = self._get_label_rotation_and_horizontal_alignment(
280-
obj, data, "y"
278+
y_tick_rotation_and_horizontal_alignment = (
279+
self._get_label_rotation_and_horizontal_alignment(obj, data, "y")
281280
)
282281
if y_tick_rotation_and_horizontal_alignment:
283282
self.axis_options.append(y_tick_rotation_and_horizontal_alignment)
@@ -600,8 +599,7 @@ def _get_ticks(data, xy, ticks, ticklabels):
600599

601600

602601
def _is_colorbar_heuristic(obj):
603-
"""Find out if the object is in fact a color bar.
604-
"""
602+
"""Find out if the object is in fact a color bar."""
605603
# TODO come up with something more accurate here
606604
# Might help:
607605
# TODO Are the colorbars exactly the l.collections.PolyCollection's?
@@ -781,8 +779,7 @@ def _handle_listed_color_map(cmap, data):
781779

782780

783781
def _scale_to_int(X, max_val):
784-
"""Scales the array X such that it contains only integers.
785-
"""
782+
"""Scales the array X such that it contains only integers."""
786783
# if max_val is None:
787784
# X = X / _gcd_array(X)
788785
X = X / max(1 / max_val, _gcd_array(X))
@@ -816,8 +813,7 @@ def _gcd(a, b):
816813

817814

818815
def _linear_interpolation(x, X, Y):
819-
"""Given two data points [X,Y], linearly interpolate those at x.
820-
"""
816+
"""Given two data points [X,Y], linearly interpolate those at x."""
821817
return (Y[1] * (x - X[0]) + Y[0] * (X[1] - x)) / (X[1] - X[0])
822818

823819

tikzplotlib/_color.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44

55
def mpl_color2xcolor(data, matplotlib_color):
6-
"""Translates a matplotlib color specification into a proper LaTeX xcolor.
7-
"""
6+
"""Translates a matplotlib color specification into a proper LaTeX xcolor."""
87
# Convert it to RGBA.
98
my_col = numpy.array(mpl.colors.ColorConverter().to_rgba(matplotlib_color))
109

tikzplotlib/_hatches.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@
3535

3636
def add_custom_pattern(mpl_hatch, pattern_name, pattern_definition=None):
3737
"""
38-
The patterns of tikzpgf are quite simple, and cannot be customized but for the
39-
color. A solution is to expose a function like this one to allow the user to
40-
populate _MP_HATCH2PGF_PATTERN with custom (hatch, pattern) pairs. mpl does no
41-
validation of the hatch string, it just ignores it if it does not recognize it,
42-
so it is possible to have <any> string be a mpl_hatch.
43-
44-
If the pattern definition is passed, it could be added at the start of the code
45-
in a similar fashion to
46-
> data["custom colors"] = {}
47-
in get_tikz_code(). tikzplotlib pattern definitions would mend the bad
48-
correspondence between the mpl hatches and tikz patterns, with custom patterns
49-
for the mpl hatches 'o' and 'O'
50-
51-
Want some opinions on this before I implement it..
52-
53-
From https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.patches.Patch.html:
54-
> Letters can be combined, in which case all the specified hatchings are done.
55-
> If same letter repeats, it increases the density of hatching of that pattern.
56-
To achieve something like this, custom patterns must be created
57-
https://tex.stackexchange.com/questions/29359/pgfplots-how-to-fill-the-area-
58-
under-a-curve-with-oblique-lines-hatching-as-a/29367#29367
38+
The patterns of tikzpgf are quite simple, and cannot be customized but for the
39+
color. A solution is to expose a function like this one to allow the user to
40+
populate _MP_HATCH2PGF_PATTERN with custom (hatch, pattern) pairs. mpl does no
41+
validation of the hatch string, it just ignores it if it does not recognize it, so
42+
it is possible to have <any> string be a mpl_hatch.
43+
44+
If the pattern definition is passed, it could be added at the start of the code in a
45+
similar fashion to
46+
> data["custom colors"] = {}
47+
in get_tikz_code(). tikzplotlib pattern definitions would mend the bad
48+
correspondence between the mpl hatches and tikz patterns, with custom patterns for
49+
the mpl hatches 'o' and 'O'.
50+
51+
Want some opinions on this before I implement it..
52+
53+
From https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.patches.Patch.html:
54+
> Letters can be combined, in which case all the specified hatchings are done.
55+
> If same letter repeats, it increases the density of hatching of that pattern.
56+
To achieve something like this, custom patterns must be created
57+
https://tex.stackexchange.com/questions/29359/pgfplots-how-to-fill-the-area-
58+
under-a-curve-with-oblique-lines-hatching-as-a/29367#29367
5959
"""
6060

6161

@@ -80,14 +80,14 @@ def __validate_hatch(hatch):
8080

8181
def _mpl_hatch2pgfp_pattern(data, hatch, color_name, color_rgba):
8282
r"""
83-
Translates a hatch from matplotlib to the corresponding patten in PGFPlots.
84-
85-
Input:
86-
hatch - str, like {'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
87-
color_name - str, xcolor or custom color name
88-
color_rgba - np.array, the rgba value of the color
89-
Output:
90-
draw_options - list, empty or with a post action string
83+
Translates a hatch from matplotlib to the corresponding patten in PGFPlots.
84+
85+
Input:
86+
hatch - str, like {'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
87+
color_name - str, xcolor or custom color name
88+
color_rgba - np.array, the rgba value of the color
89+
Output:
90+
draw_options - list, empty or with a post action string
9191
"""
9292
hatch = __validate_hatch(hatch)
9393
try:

tikzplotlib/_image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77

88
def draw_image(data, obj):
9-
"""Returns the PGFPlots code for an image environment.
10-
"""
9+
"""Returns the PGFPlots code for an image environment."""
1110
content = []
1211

1312
filename, rel_filepath = _files.new_filename(data, "img", ".png")

tikzplotlib/_legend.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77

88
def draw_legend(data, obj):
9-
"""Adds legend code.
10-
"""
9+
"""Adds legend code."""
1110
texts = []
1211
children_alignment = []
1312
for text in obj.texts:

tikzplotlib/_line2d.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212

1313
def draw_line2d(data, obj):
14-
"""Returns the PGFPlots code for an Line2D environment.
15-
"""
14+
"""Returns the PGFPlots code for an Line2D environment."""
1615
content = []
1716
addplot_options = []
1817

@@ -101,8 +100,7 @@ def draw_line2d(data, obj):
101100

102101

103102
def draw_linecollection(data, obj):
104-
"""Returns Pgfplots code for a number of patch objects.
105-
"""
103+
"""Returns Pgfplots code for a number of patch objects."""
106104
content = []
107105

108106
edgecolors = obj.get_edgecolors()

tikzplotlib/_patch.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66

77
def draw_patch(data, obj):
8-
"""Return the PGFPlots code for patches.
9-
"""
8+
"""Return the PGFPlots code for patches."""
109
if isinstance(obj, mpl.patches.FancyArrowPatch):
1110
data, draw_options = mypath.get_draw_options(
1211
data,
@@ -70,8 +69,7 @@ def zip_modulo(*seqs):
7069

7170

7271
def draw_patchcollection(data, obj):
73-
"""Returns PGFPlots code for a number of patch objects.
74-
"""
72+
"""Returns PGFPlots code for a number of patch objects."""
7573
content = []
7674

7775
# recompute the face colors
@@ -116,8 +114,7 @@ def _draw_polygon(data, obj, draw_options):
116114

117115

118116
def _draw_rectangle(data, obj, draw_options):
119-
"""Return the PGFPlots code for rectangles.
120-
"""
117+
"""Return the PGFPlots code for rectangles."""
121118
# Objects with labels are plot objects (from bar charts, etc). Even those without
122119
# labels explicitly set have a label of "_nolegend_". Everything else should be
123120
# skipped because they likely correspong to axis/legend objects which are handled by
@@ -156,8 +153,7 @@ def _draw_rectangle(data, obj, draw_options):
156153

157154

158155
def _draw_ellipse(data, obj, draw_options):
159-
"""Return the PGFPlots code for ellipses.
160-
"""
156+
"""Return the PGFPlots code for ellipses."""
161157
if isinstance(obj, mpl.patches.Circle):
162158
# circle specialization
163159
return _draw_circle(data, obj, draw_options)
@@ -180,8 +176,7 @@ def _draw_ellipse(data, obj, draw_options):
180176

181177

182178
def _draw_circle(data, obj, draw_options):
183-
"""Return the PGFPlots code for circles.
184-
"""
179+
"""Return the PGFPlots code for circles."""
185180
x, y = obj.center
186181
ff = data["float format"]
187182
do = ",".join(draw_options)

tikzplotlib/_path.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212

1313
def draw_path(data, path, draw_options=None, simplify=None):
14-
"""Adds code for drawing an ordinary path in PGFPlots (TikZ).
15-
"""
14+
"""Adds code for drawing an ordinary path in PGFPlots (TikZ)."""
1615
# For some reasons, matplotlib sometimes adds void paths which consist of
1716
# only one point and have 0 fill opacity. To not let those clutter the
1817
# output TeX file, bail out here.
@@ -112,8 +111,7 @@ def draw_path(data, path, draw_options=None, simplify=None):
112111

113112

114113
def draw_pathcollection(data, obj):
115-
"""Returns PGFPlots code for a number of patch objects.
116-
"""
114+
"""Returns PGFPlots code for a number of patch objects."""
117115
content = []
118116
# gather data
119117
assert obj.get_offsets() is not None
@@ -203,9 +201,9 @@ def draw_pathcollection(data, obj):
203201
draw_options.extend(
204202
[
205203
"visualization depends on="
206-
"{\\thisrow{sizedata} \\as\\perpointmarksize}",
204+
+ "{\\thisrow{sizedata} \\as\\perpointmarksize}",
207205
"scatter/@pre marker code/.append style="
208-
"{/tikz/mark size=\\perpointmarksize}",
206+
+ "{/tikz/mark size=\\perpointmarksize}",
209207
]
210208
)
211209

@@ -230,18 +228,18 @@ def draw_pathcollection(data, obj):
230228

231229
def get_draw_options(data, obj, ec, fc, ls, lw, hatch=None):
232230
"""Get the draw options for a given (patch) object.
233-
Get the draw options for a given (patch) object.
234-
Input:
235-
data -
236-
obj -
237-
ec - edge color
238-
fc - face color
239-
ls - linestyle
240-
lw - linewidth
241-
hatch=None - hatch, i.e., pattern within closed path
242-
Output:
243-
draw_options - list, to be ",".join(draw_options) to produce the
244-
draw options passed to PGF
231+
Get the draw options for a given (patch) object.
232+
Input:
233+
data -
234+
obj -
235+
ec - edge color
236+
fc - face color
237+
ls - linestyle
238+
lw - linewidth
239+
hatch=None - hatch, i.e., pattern within closed path
240+
Output:
241+
draw_options - list, to be ",".join(draw_options) to produce the
242+
draw options passed to PGF
245243
"""
246244
draw_options = []
247245

0 commit comments

Comments
 (0)