Skip to content

Commit be92bdc

Browse files
committed
import numpy as np
1 parent a88d4e6 commit be92bdc

File tree

9 files changed

+61
-61
lines changed

9 files changed

+61
-61
lines changed

test/test_deterministic_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# the same process, the order of axis parameters is deterministic.
99
plot_code = """
1010
import sys
11-
import numpy as np
11+
import numpy as np as np
1212
from matplotlib import pyplot as plt
1313
import tikzplotlib
1414

test/test_text_overlay.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import matplotlib.pyplot as plt
2-
import numpy
2+
import numpy as np
33
from helpers import assert_equality
44

55

66
def plot():
77
fig = plt.figure()
88

9-
xxx = numpy.linspace(0, 5)
9+
xxx = np.linspace(0, 5)
1010
yyy = xxx ** 2
1111
plt.text(
1212
1,

tikzplotlib/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import matplotlib as mpl
2-
import numpy
2+
import numpy as np
33
from matplotlib.backends.backend_pgf import (
44
common_texification as mpl_common_texification,
55
)
@@ -731,7 +731,7 @@ def _handle_linear_segmented_color_map(cmap, data):
731731
# dimension errors or memory errors in latex)
732732
# 0-1000 is the internal granularity of PGFplots.
733733
# 16300 was the maximum value for pgfplots<=1.13
734-
X = _scale_to_int(numpy.array(X), 1000)
734+
X = _scale_to_int(np.array(X), 1000)
735735

736736
color_changes = []
737737
ff = data["float format"]

tikzplotlib/_color.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import matplotlib as mpl
2-
import numpy
2+
import numpy as np
33

44

55
def mpl_color2xcolor(data, matplotlib_color):
66
"""Translates a matplotlib color specification into a proper LaTeX xcolor."""
77
# Convert it to RGBA.
8-
my_col = numpy.array(mpl.colors.ColorConverter().to_rgba(matplotlib_color))
8+
my_col = np.array(mpl.colors.ColorConverter().to_rgba(matplotlib_color))
99

1010
# If the alpha channel is exactly 0, then the color is really 'none'
1111
# regardless of the RGB channels.
@@ -18,22 +18,22 @@ def mpl_color2xcolor(data, matplotlib_color):
1818
# List white first such that for gray values, the combination
1919
# white!<x>!black is preferred over, e.g., gray!<y>!black. Note that
2020
# the order of the dictionary is respected from Python 3.6 on.
21-
"white": numpy.array([1, 1, 1]),
22-
"lightgray": numpy.array([0.75, 0.75, 0.75]),
23-
"gray": numpy.array([0.5, 0.5, 0.5]),
24-
"darkgray": numpy.array([0.25, 0.25, 0.25]),
25-
"black": numpy.array([0, 0, 0]),
21+
"white": np.array([1, 1, 1]),
22+
"lightgray": np.array([0.75, 0.75, 0.75]),
23+
"gray": np.array([0.5, 0.5, 0.5]),
24+
"darkgray": np.array([0.25, 0.25, 0.25]),
25+
"black": np.array([0, 0, 0]),
2626
#
27-
"red": numpy.array([1, 0, 0]),
28-
"green": numpy.array([0, 1, 0]),
29-
"blue": numpy.array([0, 0, 1]),
30-
"brown": numpy.array([0.75, 0.5, 0.25]),
31-
"lime": numpy.array([0.75, 1, 0]),
32-
"orange": numpy.array([1, 0.5, 0]),
33-
"pink": numpy.array([1, 0.75, 0.75]),
34-
"purple": numpy.array([0.75, 0, 0.25]),
35-
"teal": numpy.array([0, 0.5, 0.5]),
36-
"violet": numpy.array([0.5, 0, 0.5]),
27+
"red": np.array([1, 0, 0]),
28+
"green": np.array([0, 1, 0]),
29+
"blue": np.array([0, 0, 1]),
30+
"brown": np.array([0.75, 0.5, 0.25]),
31+
"lime": np.array([0.75, 1, 0]),
32+
"orange": np.array([1, 0.5, 0]),
33+
"pink": np.array([1, 0.75, 0.75]),
34+
"purple": np.array([0.75, 0, 0.25]),
35+
"teal": np.array([0, 0.5, 0.5]),
36+
"violet": np.array([0.5, 0, 0.5]),
3737
# The colors cyan, magenta, yellow, and olive are also
3838
# predefined by xcolor, but their RGB approximation of the
3939
# native CMYK values is not very good. Don't use them here.

tikzplotlib/_image.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import matplotlib as mpl
2-
import numpy
2+
import numpy as np
33
import PIL
44

55
from . import _files
@@ -30,11 +30,11 @@ def draw_image(data, obj):
3030
assert len(dims) == 3 and dims[2] in [3, 4]
3131
# convert to PIL image
3232
if obj.origin == "lower":
33-
img_array = numpy.flipud(img_array)
33+
img_array = np.flipud(img_array)
3434

3535
# Convert mpl image to PIL
36-
if img_array.dtype != numpy.uint8:
37-
img_array = numpy.uint8(img_array * 255)
36+
if img_array.dtype != np.uint8:
37+
img_array = np.uint8(img_array * 255)
3838
image = PIL.Image.fromarray(img_array)
3939

4040
# If the input image is PIL:

tikzplotlib/_legend.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import warnings
22

3-
import numpy
3+
import numpy as np
44

55
from . import _color as mycol
66

@@ -111,40 +111,40 @@ def _get_location_from_best(obj):
111111
# (or center) of the axes box.
112112
# 1. Key points of the legend
113113
lower_left_legend = x0_legend
114-
lower_right_legend = numpy.array([x1_legend[0], x0_legend[1]], dtype=numpy.float_)
115-
upper_left_legend = numpy.array([x0_legend[0], x1_legend[1]], dtype=numpy.float_)
114+
lower_right_legend = np.array([x1_legend[0], x0_legend[1]], dtype=np.float_)
115+
upper_left_legend = np.array([x0_legend[0], x1_legend[1]], dtype=np.float_)
116116
upper_right_legend = x1_legend
117117
center_legend = x0_legend + dimension_legend / 2.0
118-
center_left_legend = numpy.array(
119-
[x0_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=numpy.float_
118+
center_left_legend = np.array(
119+
[x0_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=np.float_
120120
)
121-
center_right_legend = numpy.array(
122-
[x1_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=numpy.float_
121+
center_right_legend = np.array(
122+
[x1_legend[0], x0_legend[1] + dimension_legend[1] / 2.0], dtype=np.float_
123123
)
124-
lower_center_legend = numpy.array(
125-
[x0_legend[0] + dimension_legend[0] / 2.0, x0_legend[1]], dtype=numpy.float_
124+
lower_center_legend = np.array(
125+
[x0_legend[0] + dimension_legend[0] / 2.0, x0_legend[1]], dtype=np.float_
126126
)
127-
upper_center_legend = numpy.array(
128-
[x0_legend[0] + dimension_legend[0] / 2.0, x1_legend[1]], dtype=numpy.float_
127+
upper_center_legend = np.array(
128+
[x0_legend[0] + dimension_legend[0] / 2.0, x1_legend[1]], dtype=np.float_
129129
)
130130

131131
# 2. Key points of the axes
132132
lower_left_axes = x0_axes
133-
lower_right_axes = numpy.array([x1_axes[0], x0_axes[1]], dtype=numpy.float_)
134-
upper_left_axes = numpy.array([x0_axes[0], x1_axes[1]], dtype=numpy.float_)
133+
lower_right_axes = np.array([x1_axes[0], x0_axes[1]], dtype=np.float_)
134+
upper_left_axes = np.array([x0_axes[0], x1_axes[1]], dtype=np.float_)
135135
upper_right_axes = x1_axes
136136
center_axes = x0_axes + dimension_axes / 2.0
137-
center_left_axes = numpy.array(
138-
[x0_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=numpy.float_
137+
center_left_axes = np.array(
138+
[x0_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=np.float_
139139
)
140-
center_right_axes = numpy.array(
141-
[x1_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=numpy.float_
140+
center_right_axes = np.array(
141+
[x1_axes[0], x0_axes[1] + dimension_axes[1] / 2.0], dtype=np.float_
142142
)
143-
lower_center_axes = numpy.array(
144-
[x0_axes[0] + dimension_axes[0] / 2.0, x0_axes[1]], dtype=numpy.float_
143+
lower_center_axes = np.array(
144+
[x0_axes[0] + dimension_axes[0] / 2.0, x0_axes[1]], dtype=np.float_
145145
)
146-
upper_center_axes = numpy.array(
147-
[x0_axes[0] + dimension_axes[0] / 2.0, x1_axes[1]], dtype=numpy.float_
146+
upper_center_axes = np.array(
147+
[x0_axes[0] + dimension_axes[0] / 2.0, x1_axes[1]], dtype=np.float_
148148
)
149149

150150
# 3. Compute the distances between comparable points.
@@ -161,7 +161,7 @@ def _get_location_from_best(obj):
161161
10: center_axes - center_legend, # center
162162
}
163163
for k, v in distances.items():
164-
distances[k] = numpy.linalg.norm(v, ord=2)
164+
distances[k] = np.linalg.norm(v, ord=2)
165165

166166
# 4. Take the shortest distance between key points as the final
167167
# location

tikzplotlib/_line2d.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22

3-
import numpy
3+
import numpy as np
44
from matplotlib.dates import num2date
55

66
from . import _color as mycol
@@ -222,7 +222,7 @@ def _table(obj, data): # noqa: C901
222222
except AttributeError:
223223
ydata_mask = []
224224
else:
225-
if isinstance(ydata_mask, numpy.bool_) and not ydata_mask:
225+
if isinstance(ydata_mask, np.bool_) and not ydata_mask:
226226
ydata_mask = []
227227
elif callable(ydata_mask):
228228
# pandas.Series have the method mask
@@ -268,7 +268,7 @@ def _table(obj, data): # noqa: C901
268268

269269
plot_table = []
270270
table_row_sep = data["table_row_sep"]
271-
ydata[ydata_mask] = numpy.nan
271+
ydata[ydata_mask] = np.nan
272272
if any(ydata_mask):
273273
# matplotlib jumps at masked images, while PGFPlots by default interpolates.
274274
# Hence, if we have a masked plot, make sure that PGFPlots jumps as well.

tikzplotlib/_path.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import matplotlib as mpl
2-
import numpy
2+
import numpy as np
33
from matplotlib.dates import DateConverter, num2date
44
from matplotlib.markers import MarkerStyle
55

@@ -32,7 +32,7 @@ def draw_path(data, path, draw_options=None, simplify=None):
3232
# The transform call yields warnings and it is unclear why. Perhaps
3333
# the input data is not suitable? Anyhow, this should not happen.
3434
# Comment out for now.
35-
# vert = numpy.asarray(
35+
# vert = np.asarray(
3636
# _transform_to_data_coordinates(obj, [vert[0]], [vert[1]])
3737
# )
3838
# For path codes see: http://matplotlib.org/api/path_api.html
@@ -123,7 +123,7 @@ def draw_pathcollection(data, obj):
123123

124124
if obj.get_array() is not None:
125125
draw_options.append("scatter")
126-
dd = numpy.column_stack([dd, obj.get_array()])
126+
dd = np.column_stack([dd, obj.get_array()])
127127
labels.append("colordata" + 13 * " ")
128128
draw_options.append("scatter src=explicit")
129129
table_options.extend(["x=x", "y=y", "meta=colordata"])
@@ -159,9 +159,9 @@ def draw_pathcollection(data, obj):
159159
marker0 = None
160160
for marker, path in paths.items():
161161
if (
162-
numpy.array_equal(path.codes, p.codes)
162+
np.array_equal(path.codes, p.codes)
163163
and (path.vertices.shape == p.vertices.shape)
164-
and numpy.max(numpy.abs(path.vertices - p.vertices)) < 1.0e-10
164+
and np.max(np.abs(path.vertices - p.vertices)) < 1.0e-10
165165
):
166166
marker0 = marker
167167
break
@@ -197,8 +197,8 @@ def draw_pathcollection(data, obj):
197197
if len(obj.get_sizes()) == len(dd):
198198
# See Pgfplots manual, chapter 4.25.
199199
# In Pgfplots, \mark size specifies raddi, in matplotlib circle areas.
200-
radii = numpy.sqrt(obj.get_sizes() / numpy.pi)
201-
dd = numpy.column_stack([dd, radii])
200+
radii = np.sqrt(obj.get_sizes() / np.pi)
201+
dd = np.column_stack([dd, radii])
202202
labels.append("sizedata" + 14 * " ")
203203
draw_options.extend(
204204
[
@@ -298,7 +298,7 @@ def get_draw_options(data, obj, ec, fc, ls, lw, hatch=None):
298298
if ec is None or ec_rgba[3] == 0.0:
299299
# Assuming that a hatch marker indicates that hatches are wanted, also
300300
# when the edge color is (0, 0, 0, 0), i.e., the edge is invisible
301-
h_col, h_rgba = "black", numpy.array([0, 0, 0, 1])
301+
h_col, h_rgba = "black", np.array([0, 0, 0, 1])
302302
else:
303303
h_col, h_rgba = ec_col, ec_rgba
304304
else:

tikzplotlib/_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import matplotlib.transforms
2-
import numpy
2+
import numpy as np
33

44

55
def has_legend(axes):
@@ -33,7 +33,7 @@ def transform_to_data_coordinates(obj, xdata, ydata):
3333
2. from display to data.
3434
"""
3535
if obj.axes is not None and obj.get_transform() != obj.axes.transData:
36-
points = numpy.array([xdata, ydata]).T
36+
points = np.array([xdata, ydata]).T
3737
transform = matplotlib.transforms.composite_transform_factory(
3838
obj.get_transform(), obj.axes.transData.inverted()
3939
)

0 commit comments

Comments
 (0)