Skip to content

Commit c1c2dac

Browse files
committed
Make numpy and mpl imports consistent across files
1 parent 83e0dc2 commit c1c2dac

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

ternary/heatmapping.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"""
44

55
import functools
6-
import numpy
7-
from matplotlib import pyplot
6+
import numpy as np
7+
from matplotlib import pyplot as plt
88

99
from .helpers import unzip, normalize, simplex_iterator, permute_point, project_point
1010
from .colormapping import get_cmap, colormapper, colorbar_hack
@@ -85,13 +85,13 @@ def generate_hexagon_deltas():
8585
hexagon points for the hexagonal heatmap.
8686
"""
8787

88-
zero = numpy.array([0, 0, 0])
89-
alpha = numpy.array([-1./3, 2./3, 0])
90-
deltaup = numpy.array([1./3, 1./3, 0])
91-
deltadown = numpy.array([2./3, -1./3, 0])
92-
i_vec = numpy.array([0, 1./2, -1./2])
93-
i_vec_down = numpy.array([1./2, -1./2, 0])
94-
deltaX_vec = numpy.array([1./2, 0, -1./2])
88+
zero = np.array([0, 0, 0])
89+
alpha = np.array([-1./3, 2./3, 0])
90+
deltaup = np.array([1./3, 1./3, 0])
91+
deltadown = np.array([2./3, -1./3, 0])
92+
i_vec = np.array([0, 1./2, -1./2])
93+
i_vec_down = np.array([1./2, -1./2, 0])
94+
deltaX_vec = np.array([1./2, 0, -1./2])
9595

9696
d = dict()
9797
# Corner Points
@@ -131,8 +131,8 @@ def hexagon_coordinates(i, j, k):
131131
else:
132132
signature += "1"
133133
deltas = hexagon_deltas[signature]
134-
center = numpy.array([i, j, k])
135-
return numpy.array([center + x for x in deltas])
134+
center = np.array([i, j, k])
135+
return np.array([center + x for x in deltas])
136136

137137

138138
## Heatmaps ##
@@ -228,12 +228,12 @@ def heatmap(data, scale, vmin=None, vmax=None, cmap=None, ax=None,
228228
"""
229229

230230
if not ax:
231-
fig, ax = pyplot.subplots()
231+
fig, ax = plt.subplots()
232232
# If use_rgba, make the RGBA values numpy arrays so that they can
233233
# be averaged.
234234
if use_rgba:
235235
for k, v in data.items():
236-
data[k] = numpy.array(v)
236+
data[k] = np.array(v)
237237
else:
238238
cmap = get_cmap(cmap)
239239
if vmin is None:
@@ -395,7 +395,7 @@ def svg_heatmap(data, scale, filename, vmax=None, vmin=None, style='h',
395395
if vmax is None:
396396
vmax = max(data.values())
397397

398-
height = scale * numpy.sqrt(3) / 2 + 2
398+
height = scale * np.sqrt(3) / 2 + 2
399399

400400
output_file = open(filename, 'w')
401401
output_file.write('<svg height="%s" width="%s">\n' % (height, scale))

ternary/helpers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
Helper functions and utilities for projecting to the simplex and various tasks.
33
"""
44

5-
import numpy
5+
import numpy as np
66

77

88
### Constants ###
99

10-
SQRT3 = numpy.sqrt(3)
10+
SQRT3 = np.sqrt(3)
1111
SQRT3OVER2 = SQRT3 / 2.
1212

1313
### Auxilliary Functions ###
@@ -100,7 +100,7 @@ def project_point(p, permutation=None):
100100
b = permuted[1]
101101
x = a + b/2.
102102
y = SQRT3OVER2 * b
103-
return numpy.array([x, y])
103+
return np.array([x, y])
104104

105105

106106
def planar_to_coordinates(p, scale):
@@ -121,7 +121,7 @@ def planar_to_coordinates(p, scale):
121121
y = p[1] / SQRT3OVER2
122122
x = p[0] - y / 2.
123123
z = scale - x - y
124-
return numpy.array([x, y, z])
124+
return np.array([x, y, z])
125125

126126

127127
def project_sequence(s, permutation=None):

ternary/plotting.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import matplotlib
6-
from matplotlib import pyplot
6+
from matplotlib import pyplot as plt
77
import numpy as np
88

99
from .helpers import project_sequence
@@ -66,7 +66,7 @@ def plot(points, ax=None, permutation=None, **kwargs):
6666
Any kwargs to pass through to matplotlib.
6767
"""
6868
if not ax:
69-
fig, ax = pyplot.subplots()
69+
fig, ax = plt.subplots()
7070
xs, ys = project_sequence(points, permutation=permutation)
7171
ax.plot(xs, ys, **kwargs)
7272
return ax
@@ -91,7 +91,7 @@ def plot_colored_trajectory(points, cmap=None, ax=None, permutation=None,
9191
Any kwargs to pass through to matplotlib.
9292
"""
9393
if not ax:
94-
fig, ax = pyplot.subplots()
94+
fig, ax = plt.subplots()
9595
cmap = get_cmap(cmap)
9696
xs, ys = project_sequence(points, permutation=permutation)
9797

@@ -143,7 +143,7 @@ def scatter(points, ax=None, permutation=None, colorbar=False, colormap=None,
143143
Any kwargs to pass through to matplotlib.
144144
"""
145145
if not ax:
146-
fig, ax = pyplot.subplots()
146+
fig, ax = plt.subplots()
147147
xs, ys = project_sequence(points, permutation=permutation)
148148
ax.scatter(xs, ys, vmin=vmin, vmax=vmax, **kwargs)
149149

0 commit comments

Comments
 (0)