Skip to content

Commit

Permalink
Various updates for matplotlib 3.1 compatibility (#3877)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Aug 5, 2019
1 parent 64aec1b commit cab8b05
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ requirements:
test:
requires:
- nose
- matplotlib<=3.0
imports:
- holoviews
commands:
Expand Down
3 changes: 3 additions & 0 deletions holoviews/plotting/mpl/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ def _set_aspect(self, axes, aspect):
"""
Set the aspect on the axes based on the aspect setting.
"""
if self.projection == '3d':
return

if ((isinstance(aspect, util.basestring) and aspect != 'square') or
self.data_aspect):
data_ratio = self.data_aspect or aspect
Expand Down
4 changes: 3 additions & 1 deletion holoviews/plotting/mpl/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ def init_artists(self, ax, plot_args, plot_kwargs):
colorbar = self.handles.get('cbar')
if colorbar:
colorbar.set_norm(artist.norm)
colorbar.set_array(artist.get_array())
if hasattr(colorbar, 'set_array'):
# Compatibility with mpl < 3
colorbar.set_array(artist.get_array())
colorbar.set_clim(artist.get_clim())
colorbar.update_normal(artist)
return {'artist': artist, 'locs': locs}
Expand Down
18 changes: 9 additions & 9 deletions holoviews/tests/plotting/matplotlib/testgraphplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_plot_simple_graph(self):
plot = mpl_renderer.get_plot(self.graph)
nodes = plot.handles['nodes']
edges = plot.handles['edges']
self.assertEqual(nodes.get_offsets(), self.graph.nodes.array([0, 1]))
self.assertEqual(np.asarray(nodes.get_offsets()), self.graph.nodes.array([0, 1]))
self.assertEqual([p.vertices for p in edges.get_paths()],
[p.array() for p in self.graph.edgepaths.split()])

Expand All @@ -59,7 +59,7 @@ def test_plot_graph_numerically_colored_nodes(self):
g = self.graph3.opts(plot=dict(color_index='Weight'), style=dict(cmap='viridis'))
plot = mpl_renderer.get_plot(g)
nodes = plot.handles['nodes']
self.assertEqual(nodes.get_array(), self.weights)
self.assertEqual(np.asarray(nodes.get_array()), self.weights)
self.assertEqual(nodes.get_clim(), (self.weights.min(), self.weights.max()))

def test_plot_graph_categorical_colored_edges(self):
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_graph_op_node_color_linear(self):
graph = Graph((edges, nodes)).options(node_color='color')
plot = mpl_renderer.get_plot(graph)
artist = plot.handles['nodes']
self.assertEqual(artist.get_array(), np.array([0.5, 1.5, 2.5]))
self.assertEqual(np.asarray(artist.get_array()), np.array([0.5, 1.5, 2.5]))
self.assertEqual(artist.get_clim(), (0.5, 2.5))

def test_graph_op_node_color_linear_update(self):
Expand All @@ -150,7 +150,7 @@ def test_graph_op_node_color_categorical(self):
graph = Graph((edges, nodes)).options(node_color='color')
plot = mpl_renderer.get_plot(graph)
artist = plot.handles['nodes']
self.assertEqual(artist.get_array(), np.array([0, 1, 0]))
self.assertEqual(np.asarray(artist.get_array()), np.array([0, 1, 0]))

def test_graph_op_node_size(self):
edges = [(0, 1), (0, 2)]
Expand Down Expand Up @@ -306,7 +306,7 @@ def test_plot_simple_trimesh(self):
nodes = plot.handles['nodes']
edges = plot.handles['edges']
self.assertIsInstance(edges, LineCollection)
self.assertEqual(nodes.get_offsets(), self.trimesh.nodes.array([0, 1]))
self.assertEqual(np.asarray(nodes.get_offsets()), self.trimesh.nodes.array([0, 1]))
self.assertEqual([p.vertices for p in edges.get_paths()],
[p.array() for p in self.trimesh._split_edgepaths.split()])

Expand All @@ -315,7 +315,7 @@ def test_plot_simple_trimesh_filled(self):
nodes = plot.handles['nodes']
edges = plot.handles['edges']
self.assertIsInstance(edges, PolyCollection)
self.assertEqual(nodes.get_offsets(), self.trimesh.nodes.array([0, 1]))
self.assertEqual(np.asarray(nodes.get_offsets()), self.trimesh.nodes.array([0, 1]))
paths = self.trimesh._split_edgepaths.split(datatype='array')
self.assertEqual([p.vertices[:4] for p in edges.get_paths()],
paths)
Expand Down Expand Up @@ -364,7 +364,7 @@ def test_trimesh_op_node_color_linear(self):
trimesh = TriMesh((edges, Nodes(nodes, vdims='color'))).options(node_color='color')
plot = mpl_renderer.get_plot(trimesh)
artist = plot.handles['nodes']
self.assertEqual(artist.get_array(), np.array([2, 1, 3, 4]))
self.assertEqual(np.asarray(artist.get_array()), np.array([2, 1, 3, 4]))
self.assertEqual(artist.get_clim(), (1, 4))

def test_trimesh_op_node_color_categorical(self):
Expand All @@ -373,7 +373,7 @@ def test_trimesh_op_node_color_categorical(self):
trimesh = TriMesh((edges, Nodes(nodes, vdims='color'))).options(node_color='color')
plot = mpl_renderer.get_plot(trimesh)
artist = plot.handles['nodes']
self.assertEqual(artist.get_array(), np.array([0, 1, 2, 0]))
self.assertEqual(np.asarray(artist.get_array()), np.array([0, 1, 2, 0]))
self.assertEqual(artist.get_clim(), (0, 2))

def test_trimesh_op_node_size(self):
Expand Down Expand Up @@ -494,7 +494,7 @@ def test_chord_node_color_style_mapping(self):
plot = mpl_renderer.get_plot(g)
arcs = plot.handles['arcs']
nodes = plot.handles['nodes']
self.assertEqual(nodes.get_array(), np.array([0, 1, 2]))
self.assertEqual(np.asarray(nodes.get_array()), np.array([0, 1, 2]))
self.assertEqual(arcs.get_array(), np.array([0, 1, 2]))
self.assertEqual(nodes.get_clim(), (0, 2))
self.assertEqual(arcs.get_clim(), (0, 2))
Expand Down
4 changes: 2 additions & 2 deletions holoviews/tests/plotting/matplotlib/testpointplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_point_linear_color_op(self):
vdims='color').options(color='color')
plot = mpl_renderer.get_plot(points)
artist = plot.handles['artist']
self.assertEqual(artist.get_array(), np.array([0, 1, 2]))
self.assertEqual(np.asarray(artist.get_array()), np.array([0, 1, 2]))
self.assertEqual(artist.get_clim(), (0, 2))

def test_point_linear_color_op_update(self):
Expand All @@ -237,7 +237,7 @@ def test_point_categorical_color_op(self):
vdims='color').options(color='color')
plot = mpl_renderer.get_plot(points)
artist = plot.handles['artist']
self.assertEqual(artist.get_array(), np.array([0, 1, 0]))
self.assertEqual(np.asarray(artist.get_array()), np.array([0, 1, 0]))
self.assertEqual(artist.get_clim(), (0, 1))

def test_point_size_op(self):
Expand Down

0 comments on commit cab8b05

Please sign in to comment.