Skip to content

Commit 5b2dbdb

Browse files
committed
Trame support to get interactive plots in jupyter
1 parent 19d119c commit 5b2dbdb

File tree

6 files changed

+1032
-253
lines changed

6 files changed

+1032
-253
lines changed

development/Examples/Basics/1. Import and plot.ipynb

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
{
1414
"cell_type": "code",
15-
"execution_count": null,
15+
"execution_count": 1,
1616
"id": "ef369740-53d2-455d-9ec4-158d967cc732",
1717
"metadata": {},
1818
"outputs": [],
@@ -21,7 +21,7 @@
2121
"from fracability import Entities # import the Entities class\n",
2222
"\n",
2323
"# The following is only for jupyter to avoid matplotlib inline plots\n",
24-
"%matplotlib qt5"
24+
"# %matplotlib qt5"
2525
]
2626
},
2727
{
@@ -34,7 +34,7 @@
3434
},
3535
{
3636
"cell_type": "code",
37-
"execution_count": null,
37+
"execution_count": 2,
3838
"id": "5c18daf8-8505-4ee4-8fb8-c2c9be2b97a9",
3939
"metadata": {},
4040
"outputs": [],
@@ -44,17 +44,25 @@
4444
},
4545
{
4646
"cell_type": "code",
47-
"execution_count": null,
47+
"execution_count": 3,
4848
"id": "b1553b23-c08b-4461-a16d-6807d4d42991",
4949
"metadata": {},
50-
"outputs": [],
50+
"outputs": [
51+
{
52+
"name": "stdout",
53+
"output_type": "stream",
54+
"text": [
55+
"['Set_b.shp', 'Set_a.shp', 'Set_c.shp', 'Interpretation_boundary.shp']\n"
56+
]
57+
}
58+
],
5159
"source": [
5260
"print(pontrelli_data.available_data)"
5361
]
5462
},
5563
{
5664
"cell_type": "code",
57-
"execution_count": null,
65+
"execution_count": 4,
5866
"id": "c7f9edb7-7488-4722-81bd-dfff2d9219b8",
5967
"metadata": {},
6068
"outputs": [],
@@ -79,7 +87,7 @@
7987
},
8088
{
8189
"cell_type": "code",
82-
"execution_count": null,
90+
"execution_count": 5,
8391
"id": "b9744c5a-6891-435e-a586-f35a92623b23",
8492
"metadata": {},
8593
"outputs": [],
@@ -129,12 +137,60 @@
129137
{
130138
"cell_type": "code",
131139
"execution_count": null,
140+
"id": "7b67f1d9-a4df-4666-8928-37f2fc103939",
141+
"metadata": {},
142+
"outputs": [],
143+
"source": [
144+
"pv.Cone().plot()"
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": 7,
132150
"id": "571ae15c-a1cd-4b69-a050-365acd921456",
133151
"metadata": {},
152+
"outputs": [
153+
{
154+
"data": {
155+
"application/vnd.jupyter.widget-view+json": {
156+
"model_id": "75cc5bc8b9094ac0bc9f6cbdddaf9d6c",
157+
"version_major": 2,
158+
"version_minor": 0
159+
},
160+
"text/plain": [
161+
"Widget(value='<iframe src=\"http://localhost:34109/index.html?ui=P_0x7463d1f10370_1&reconnect=auto\" class=\"pyvi…"
162+
]
163+
},
164+
"metadata": {},
165+
"output_type": "display_data"
166+
},
167+
{
168+
"data": {
169+
"application/vnd.jupyter.widget-view+json": {
170+
"model_id": "96a690370138482e8d335d33688d5ba7",
171+
"version_major": 2,
172+
"version_minor": 0
173+
},
174+
"text/plain": [
175+
"Widget(value='<iframe src=\"http://localhost:34109/index.html?ui=P_0x7463d1f122f0_2&reconnect=auto\" class=\"pyvi…"
176+
]
177+
},
178+
"metadata": {},
179+
"output_type": "display_data"
180+
}
181+
],
182+
"source": [
183+
"set_a.vtk_plot(linewidth=2, color='blue',notebook=True) # set custom linewidths and color \n",
184+
"boundary.vtk_plot()"
185+
]
186+
},
187+
{
188+
"cell_type": "code",
189+
"execution_count": null,
190+
"id": "6b2c9036-90bd-4d8e-a301-8d8b0a6732b0",
191+
"metadata": {},
134192
"outputs": [],
135193
"source": [
136-
"set_a.vtk_plot(linewidth=2, color='blue') # set custom linewidths and color \n",
137-
"boundary.vtk_plot()\n",
138194
"set_a.mat_plot(linewidth=2, color='blue') # set custom linewidths and color \n",
139195
"boundary.mat_plot(linewidth=2, color='black')"
140196
]

docs/Tutorials/notebooks/Basic/1. Import and plot.ipynb

Lines changed: 895 additions & 151 deletions
Large diffs are not rendered by default.

fracability/Entities.py

Lines changed: 41 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def mat_plot(self, markersize=7, return_plot=False, show_plot=True):
202202
"""
203203
plts.matplot_nodes(self, markersize, return_plot, show_plot)
204204

205-
def vtk_plot(self, markersize=7, return_plot=False, show_plot=True):
205+
def vtk_plot(self, markersize=7, return_plot=False, show_plot=True, notebook=True):
206206
"""
207207
Plot Nodes object with VTK
208208
:param markersize:
@@ -211,7 +211,7 @@ def vtk_plot(self, markersize=7, return_plot=False, show_plot=True):
211211
:return:
212212
"""
213213

214-
plts.vtkplot_nodes(self, markersize, return_plot, show_plot)
214+
plts.vtkplot_nodes(self, markersize, return_plot, show_plot, notebook=notebook)
215215

216216
def ternary_plot(self):
217217
plts.matplot_ternary(self)
@@ -396,7 +396,8 @@ def vtk_plot(self,
396396
color_set=False,
397397
return_plot=False,
398398
show_plot=True,
399-
display_property: str = None):
399+
display_property: str = None,
400+
notebook=True):
400401
"""
401402
Plot fracture object with VTK
402403
:param linewidth:
@@ -408,12 +409,13 @@ def vtk_plot(self,
408409
:return:
409410
"""
410411
plts.vtkplot_fractures(self,
411-
linewidth,
412-
color,
413-
color_set,
414-
return_plot,
415-
show_plot,
416-
display_property)
412+
linewidth=linewidth,
413+
color=color,
414+
color_set=color_set,
415+
return_plot=return_plot,
416+
show_plot=show_plot,
417+
display_property=display_property,
418+
notebook=notebook)
417419

418420

419421
class Boundary(BaseEntity):
@@ -584,7 +586,8 @@ def vtk_plot(self,
584586
color='red',
585587
color_set=False,
586588
return_plot=False,
587-
show_plot=True):
589+
show_plot=True,
590+
notebook=True):
588591
"""
589592
Plot Boundary object with vtk
590593
:param linewidth:
@@ -595,10 +598,11 @@ def vtk_plot(self,
595598
:return:
596599
"""
597600
plts.vtkplot_boundaries(self,
598-
linewidth,
599-
color,
600-
return_plot,
601-
show_plot)
601+
linewidth=linewidth,
602+
color=color,
603+
return_plot=return_plot,
604+
show_plot=show_plot,
605+
notebook=notebook)
602606

603607

604608
class Backbone(Fractures):
@@ -837,19 +841,6 @@ def activate_nodes(self, node_type: list = None):
837841
for t in node_type:
838842
self.entity_df.loc[self.entity_df['n_type'] == t, 'active'] = 1
839843

840-
def deactivate_nodes(self, node_type: list = None):
841-
"""
842-
Method that activates the nodes provided in the node_type list.
843-
:param node_type: List of node types to be activated
844-
"""
845-
846-
if node_type is None:
847-
self.entity_df.loc[self.entity_df['type'] == 'nodes', 'active'] = 0
848-
else:
849-
self.entity_df.loc[self.entity_df['type'] == 'nodes', 'active'] = 1
850-
for t in node_type:
851-
self.entity_df.loc[self.entity_df['n_type'] == t, 'active'] = 0
852-
853844
def is_type_active(self, node_type: int) -> bool:
854845
"""
855846
Method used to return if a given node type is active in the fracture network
@@ -971,21 +962,9 @@ def activate_fractures(self, set_n: list = None):
971962
self.entity_df.loc[self.entity_df['type'] == 'fractures', 'active'] = 1
972963
else:
973964
self.entity_df.loc[self.entity_df['type'] == 'fractures', 'active'] = 0
974-
for n in set_n:
975-
self.entity_df.loc[self.entity_df['f_set'] == n, 'active'] = 1
976-
977-
def deactivate_fractures(self, set_n: list = None):
978-
"""
979-
Method that activates the fractures provided in the set_n list.
980-
:param set_n: List of sets to be activated
981-
"""
982-
983-
if set_n is None:
984-
self.entity_df.loc[self.entity_df['type'] == 'fractures', 'active'] = 0
985-
else:
986-
self.entity_df.loc[self.entity_df['type'] == 'fractures', 'active'] = 1
987-
for n in set_n:
988-
self.entity_df.loc[self.entity_df['f_set'] == n, 'active'] = 0
965+
if len(set_n) > 0:
966+
for n in set_n:
967+
self.entity_df.loc[self.entity_df['f_set'] == n, 'active'] = 1
989968

990969
def is_set_active(self, set_n: int) -> bool:
991970
"""
@@ -1113,24 +1092,6 @@ def activate_boundaries(self, group_n: list = None):
11131092
for n in group_n:
11141093
self.entity_df.loc[self.entity_df['b_group'] == n, 'active'] = 1
11151094

1116-
def deactivate_boundaries(self, group_n: list = None):
1117-
1118-
"""
1119-
Method that deactivates the boundary provided in the group_n list.
1120-
:param group_n: List of groups to be deactivated
1121-
1122-
Note
1123-
-------
1124-
If group_n is none then all boundaries groups are deactivated
1125-
"""
1126-
1127-
if group_n is None:
1128-
self.entity_df.loc[self.entity_df['type'] == 'boundary', 'active'] = 0
1129-
else:
1130-
self.entity_df.loc[self.entity_df['type'] == 'boundary', 'active'] = 1
1131-
for n in group_n:
1132-
self.entity_df.loc[self.entity_df['b_group'] == n, 'active'] = 0
1133-
11341095
def is_group_active(self, group_n: int) -> bool:
11351096
"""
11361097
Method used to return if a given boundary group is active in the fracture network
@@ -1342,7 +1303,8 @@ def vtk_plot(self,
13421303
boundary_color='red',
13431304
color_set=False,
13441305
show_plot=True,
1345-
return_plot=False):
1306+
return_plot=False,
1307+
notebook=True):
13461308
"""
13471309
Method used to plot the fracture network using vtk
13481310
:param markersize:
@@ -1357,14 +1319,15 @@ def vtk_plot(self,
13571319
"""
13581320

13591321
plts.vtkplot_frac_net(self,
1360-
markersize,
1361-
fracture_linewidth,
1362-
boundary_linewidth,
1363-
fracture_color,
1364-
boundary_color,
1365-
color_set,
1366-
show_plot,
1367-
return_plot)
1322+
markersize=markersize,
1323+
fracture_linewidth=fracture_linewidth,
1324+
boundary_linewidth=boundary_linewidth,
1325+
fracture_color=fracture_color,
1326+
boundary_color=boundary_color,
1327+
color_set=color_set,
1328+
show_plot=show_plot,
1329+
return_plot=return_plot,
1330+
notebook=notebook)
13681331

13691332
def backbone_plot(self,
13701333
method='vtk',
@@ -1373,19 +1336,21 @@ def backbone_plot(self,
13731336
fracture_color='black',
13741337
boundary_color='red',
13751338
return_plot=False,
1376-
show_plot=True):
1339+
show_plot=True,
1340+
notebook=True):
13771341
"""
13781342
Method used to plot the fracture network using vtk
13791343
:return:
13801344
"""
13811345
if method == 'vtk':
13821346
plts.vtkplot_backbone(self,
1383-
fracture_linewidth,
1384-
boundary_linewidth,
1385-
fracture_color,
1386-
boundary_color,
1387-
return_plot,
1388-
show_plot)
1347+
fracture_linewidth=fracture_linewidth,
1348+
boundary_linewidth=boundary_linewidth,
1349+
fracture_color=fracture_color,
1350+
boundary_color=boundary_color,
1351+
return_plot=return_plot,
1352+
show_plot=show_plot,
1353+
notebook=notebook)
13891354
elif method == 'matplot':
13901355
plts.matplot_backbone(self,
13911356
fracture_linewidth,

0 commit comments

Comments
 (0)