From a00d1b4e358df0b238ccb60a2d7bb6b74717a1ef Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Sat, 14 Nov 2020 16:45:38 -0800 Subject: Enable mayavi in sphinx gallery. (#4297) * Enable mayavi in sphinx gallery. * Add mayavi deps to example requirements. * Install vtk before mayavi * Don't popup Mayavi windows * Display offscreen * Borrow mayavi CI conf from sphinx-gallery * Grab dependencies as specified in sphinx-gallery conf. * Set up virtual frame buffer so mayavi can import/run headless. Co-authored-by: Jarrod Millman --- examples/3d_drawing/mayavi2_spring.py | 41 ---------------------------- examples/3d_drawing/plot_mayavi2_spring.py | 43 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 41 deletions(-) delete mode 100644 examples/3d_drawing/mayavi2_spring.py create mode 100644 examples/3d_drawing/plot_mayavi2_spring.py (limited to 'examples') diff --git a/examples/3d_drawing/mayavi2_spring.py b/examples/3d_drawing/mayavi2_spring.py deleted file mode 100644 index 7aa0b30a..00000000 --- a/examples/3d_drawing/mayavi2_spring.py +++ /dev/null @@ -1,41 +0,0 @@ -""" -======= -Mayavi2 -======= - -""" - -import networkx as nx -import numpy as np -from mayavi import mlab - -# some graphs to try -# H=nx.krackhardt_kite_graph() -# H=nx.Graph();H.add_edge('a','b');H.add_edge('a','c');H.add_edge('a','d') -# H=nx.grid_2d_graph(4,5) -H = nx.cycle_graph(20) - -# reorder nodes from 0,len(G)-1 -G = nx.convert_node_labels_to_integers(H) -# 3d spring layout -pos = nx.spring_layout(G, dim=3) -# numpy array of x,y,z positions in sorted node order -xyz = np.array([pos[v] for v in sorted(G)]) -# scalar colors -scalars = np.array(list(G.nodes())) + 5 - -pts = mlab.points3d( - xyz[:, 0], - xyz[:, 1], - xyz[:, 2], - scalars, - scale_factor=0.1, - scale_mode="none", - colormap="Blues", - resolution=20, -) - -pts.mlab_source.dataset.lines = np.array(list(G.edges())) -tube = mlab.pipeline.tube(pts, tube_radius=0.01) -mlab.pipeline.surface(tube, color=(0.8, 0.8, 0.8)) -mlab.show() diff --git a/examples/3d_drawing/plot_mayavi2_spring.py b/examples/3d_drawing/plot_mayavi2_spring.py new file mode 100644 index 00000000..bec09694 --- /dev/null +++ b/examples/3d_drawing/plot_mayavi2_spring.py @@ -0,0 +1,43 @@ +""" +======= +Mayavi2 +======= + +""" + +import networkx as nx +import numpy as np +from mayavi import mlab + +# some graphs to try +# H=nx.krackhardt_kite_graph() +# H=nx.Graph();H.add_edge('a','b');H.add_edge('a','c');H.add_edge('a','d') +# H=nx.grid_2d_graph(4,5) +H = nx.cycle_graph(20) + +# reorder nodes from 0,len(G)-1 +G = nx.convert_node_labels_to_integers(H) +# 3d spring layout +pos = nx.spring_layout(G, dim=3, seed=1001) +# numpy array of x,y,z positions in sorted node order +xyz = np.array([pos[v] for v in sorted(G)]) +# scalar colors +scalars = np.array(list(G.nodes())) + 5 + +mlab.figure() + +pts = mlab.points3d( + xyz[:, 0], + xyz[:, 1], + xyz[:, 2], + scalars, + scale_factor=0.1, + scale_mode="none", + colormap="Blues", + resolution=20, +) + +pts.mlab_source.dataset.lines = np.array(list(G.edges())) +tube = mlab.pipeline.tube(pts, tube_radius=0.01) +mlab.pipeline.surface(tube, color=(0.8, 0.8, 0.8)) +mlab.orientation_axes() -- cgit v1.2.1