Skip to content

Commit

Permalink
STY: rm unnecessary blank lines, indent parenthetical line continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
johnyf committed Apr 19, 2017
1 parent 7535ff3 commit c326cdb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
22 changes: 3 additions & 19 deletions polytope/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@


def plot_partition(
ppp, trans=None, ppp2trans=None, only_adjacent=False,
ax=None, plot_numbers=True, color_seed=None
):
ppp, trans=None, ppp2trans=None, only_adjacent=False,
ax=None, plot_numbers=True, color_seed=None):
"""Plot partition with arrows from digraph.
For filtering edges based on label use L{plot_ts_on_partition}.
Expand Down Expand Up @@ -85,10 +84,8 @@ def plot_partition(
msg += 'so ppp2trans required to define state order,\n'
msg += 'used when converting the graph to an adjacency matrix.'
raise Exception(msg)

trans = nx.to_numpy_matrix(trans, nodelist=ppp2trans)
trans = np.array(trans)

l,u = ppp.domain.bounding_box
arr_size = (u[0,0]-l[0,0])/50.0
ax = pc._newax(ax)
Expand All @@ -100,16 +97,13 @@ def plot_partition(
trans = 'none'
else:
ax.set_title('Adjacency from given Transitions')

ax.set_xlim(l[0,0],u[0,0])
ax.set_ylim(l[1,0],u[1,0])

# repeatable coloring ?
if color_seed is not None:
prng = np.random.RandomState(color_seed)
else:
prng = np.random.RandomState()

# plot polytope patches
for i, reg in enumerate(ppp.regions):
# select random color,
Expand All @@ -120,12 +114,10 @@ def plot_partition(
reg.plot(color=col, ax=ax)
if plot_numbers:
reg.text(str(i), ax, color='red')

# not show trans ?
if trans is 'none':
mpl.pyplot.show()
return ax

# plot transition arrows between patches
rows, cols = np.nonzero(trans)
for i, j in zip(rows, cols):
Expand All @@ -135,9 +127,7 @@ def plot_partition(
continue

plot_transition_arrow(ppp.regions[i], ppp.regions[j], ax, arr_size)

mpl.pyplot.show()

return ax


Expand All @@ -154,26 +144,20 @@ def plot_transition_arrow(polyreg0, polyreg1, ax, arr_size=None):
# brevity
p0 = polyreg0
p1 = polyreg1

rc0, xc0 = pc.cheby_ball(p0)
rc1, xc1 = pc.cheby_ball(p1)

if np.sum(np.abs(xc1-xc0)) < 1e-7:
return None

if arr_size is None:
l,u = polyreg1.bounding_box
arr_size = (u[0, 0] - l[0, 0]) / 25.0

#TODO: 3d
x = xc0[0]
y = xc0[1]
dx = xc1[0] - xc0[0]
dy = xc1[1] - xc0[1]
arrow = patches.Arrow(
float(x), float(y), float(dx), float(dy),
width=arr_size, color='black'
)
width=arr_size, color='black')
ax.add_patch(arrow)

return arrow
17 changes: 6 additions & 11 deletions polytope/polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,12 @@ def plot(self, ax=None, color=None,
poly = _get_patch(
self, facecolor=color, hatch=hatch,
alpha=alpha, linestyle='dashed', linewidth=3,
edgecolor='black'
)
edgecolor='black')
ax.add_patch(poly)

return ax

def text(self, txt, ax=None, color='black'):
"""Plot text at chebyshev center.
"""
"""Plot text at chebyshev center."""
_plot_text(self, txt, ax, color)


Expand Down Expand Up @@ -650,7 +647,7 @@ def bounding_box(self):

def plot(self, ax=None, color=None,
hatch=None, alpha=1.0):
#TODO optional arg for text label
# TODO optional arg for text label
if self.dim != 2:
raise Exception("Cannot plot region of dimension larger than 2")
if not is_fulldim(self):
Expand All @@ -662,7 +659,6 @@ def plot(self, ax=None, color=None,
for poly2 in self.list_poly:
# TODO hatched polytopes in same region
poly2.plot(ax, color=color, hatch=hatch, alpha=alpha)

return ax

def text(self, txt, ax=None, color='black'):
Expand Down Expand Up @@ -2107,18 +2103,18 @@ def grid_region(polyreg, res=None):
"""Grid within polytope or region.
@type polyreg: L{Polytope} or L{Region}
@param res: resolution of grid
"""
# grid corners
bbox = polyreg.bounding_box
bbox = np.hstack(bbox)
dom = bbox.flatten()

# grid resolution
density = 8
if res is None:
res = list()
for i in xrange(0, dom.size, 2):
L = dom[i+1] - dom[i]
L = dom[i + 1] - dom[i]
res += [density * L]
linspaces = list()
for i, n in enumerate(res):
Expand All @@ -2129,7 +2125,6 @@ def grid_region(polyreg, res=None):
points = np.meshgrid(*linspaces)
x = np.vstack(map(np.ravel, points))
x = x[:, polyreg.are_inside(x)]

return (x, res)


Expand Down

0 comments on commit c326cdb

Please sign in to comment.