Skip to content

Commit b0dc8af

Browse files
committed
moving plotly functions
1 parent 83029c3 commit b0dc8af

File tree

2 files changed

+45
-38
lines changed

2 files changed

+45
-38
lines changed

my_graph.py

+1-35
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __repr__(self):
8989
if self.name:
9090
return self.name
9191
else:
92-
return "(%.2f,%.2f)" % (self.x, self.y)
92+
return "(%.3f,%.3f)" % (self.x, self.y)
9393

9494
def __eq__(self, other):
9595
return self.loc == other.loc
@@ -1066,40 +1066,6 @@ def plot_weak_duals(self, stack=None, colors=None, width=None,
10661066
plt.axes().set_aspect(aspect=1)
10671067
plt.axis('off')
10681068

1069-
def myGraph_to_plotly_traces(self):
1070-
"""myGraph to plotly trace """
1071-
1072-
# add the edges as disconnected lines in a trace
1073-
edge_trace = Scatter(x=[], y=[], mode='lines',
1074-
name='Parcel Boundaries',
1075-
line=Line(color='grey', width=0.5))
1076-
road_trace = Scatter(x=[], y=[], mode='lines',
1077-
name='Road Boundaries',
1078-
line=Line(color='black', width=2))
1079-
interior_trace = Scatter(x=[], y=[], mode='lines',
1080-
name='Interior Parcels',
1081-
line=Line(color='red', width=2.5))
1082-
barrier_trace = Scatter(x=[], y=[], mode='lines',
1083-
name='Barriers',
1084-
line=Line(color='green', width=0.75))
1085-
1086-
for i in self.connected_components():
1087-
for edge in i.myedges():
1088-
x0, y0 = edge.nodes[0].loc
1089-
x1, y1 = edge.nodes[1].loc
1090-
edge_trace['x'] += [x0, x1, None]
1091-
edge_trace['y'] += [y0, y1, None]
1092-
if edge.road:
1093-
road_trace['x'] += [x0, x1, None]
1094-
road_trace['y'] += [y0, y1, None]
1095-
if edge.interior:
1096-
interior_trace['x'] += [x0, x1, None]
1097-
interior_trace['y'] += [y0, y1, None]
1098-
if edge.barrier:
1099-
barrier_trace['x'] += [x0, x1, None]
1100-
barrier_trace['y'] += [y0, y1, None]
1101-
1102-
return edge_trace, road_trace, interior_trace, barrier_trace
11031069

11041070

11051071
if __name__ == "__main__":

my_graph_helpers.py

+44-3
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,48 @@ def make_colormap(seq):
844844
return mcolors.LinearSegmentedColormap('CustomMap', cdict)
845845

846846

847-
def plotly_notebook(traces, filename=None, title=None):
847+
848+
def plotly_traces(myG):
849+
"""myGraph to plotly trace """
850+
851+
# add the edges as disconnected lines in a trace
852+
edge_trace = Scatter(x=[], y=[], mode='lines',
853+
name='Parcel Boundaries',
854+
line=Line(color='grey', width=0.5))
855+
road_trace = Scatter(x=[], y=[], mode='lines',
856+
name='Road Boundaries',
857+
line=Line(color='black', width=2))
858+
interior_trace = Scatter(x=[], y=[], mode='lines',
859+
name='Interior Parcels',
860+
line=Line(color='red', width=2.5))
861+
barrier_trace = Scatter(x=[], y=[], mode='lines',
862+
name='Barriers',
863+
line=Line(color='green', width=0.75))
864+
865+
for i in myG.connected_components():
866+
for edge in i.myedges():
867+
x0, y0 = edge.nodes[0].loc
868+
x1, y1 = edge.nodes[1].loc
869+
edge_trace['x'] += [x0, x1, None]
870+
edge_trace['y'] += [y0, y1, None]
871+
if edge.road:
872+
road_trace['x'] += [x0, x1, None]
873+
road_trace['y'] += [y0, y1, None]
874+
if edge.interior:
875+
interior_trace['x'] += [x0, x1, None]
876+
interior_trace['y'] += [y0, y1, None]
877+
if edge.barrier:
878+
barrier_trace['x'] += [x0, x1, None]
879+
barrier_trace['y'] += [y0, y1, None]
880+
881+
return [edge_trace, road_trace, interior_trace, barrier_trace]
882+
883+
884+
def plotly_graph(traces, filename=None, title=None):
885+
""" use py.iplot(fig,filename) after this function in ipython notrbook to
886+
show the resulting plotly figure inline, or url=py.plot(fig,filename) to
887+
just get url of resulting fig and not plot inline. """
888+
848889
if filename is None:
849890
filename = "plotly_graph"
850891
fig = Figure(data=Data(traces),
@@ -854,7 +895,8 @@ def plotly_notebook(traces, filename=None, title=None):
854895
showticklabels=False),
855896
yaxis=YAxis(showgrid=False, zeroline=False,
856897
showticklabels=False)))
857-
py.iplot(fig, filename=filename)
898+
#py.iplot(fig, filename=filename)
899+
return fig, filename
858900

859901

860902
######################
@@ -1068,7 +1110,6 @@ def json_test(test_geojson):
10681110
print test_request.json()
10691111

10701112

1071-
10721113
def __centroid_test():
10731114
n = {}
10741115
n[1] = mg.MyNode((0, 0))

0 commit comments

Comments
 (0)