From cab8b05e725f6f11fc6ef90f9bc91ddaea2449ff Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 5 Aug 2019 14:29:20 +0200 Subject: [PATCH] Various updates for matplotlib 3.1 compatibility (#3877) --- conda.recipe/meta.yaml | 1 + holoviews/plotting/mpl/element.py | 3 +++ holoviews/plotting/mpl/raster.py | 4 +++- .../tests/plotting/matplotlib/testgraphplot.py | 18 +++++++++--------- .../tests/plotting/matplotlib/testpointplot.py | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 69094cb2a3..10aaa89e33 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -36,6 +36,7 @@ requirements: test: requires: - nose + - matplotlib<=3.0 imports: - holoviews commands: diff --git a/holoviews/plotting/mpl/element.py b/holoviews/plotting/mpl/element.py index e58a85e47f..f42eec7e74 100644 --- a/holoviews/plotting/mpl/element.py +++ b/holoviews/plotting/mpl/element.py @@ -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 diff --git a/holoviews/plotting/mpl/raster.py b/holoviews/plotting/mpl/raster.py index 745dc6b868..cbbc8b9e0a 100644 --- a/holoviews/plotting/mpl/raster.py +++ b/holoviews/plotting/mpl/raster.py @@ -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} diff --git a/holoviews/tests/plotting/matplotlib/testgraphplot.py b/holoviews/tests/plotting/matplotlib/testgraphplot.py index fcd2728ea2..52e090711f 100644 --- a/holoviews/tests/plotting/matplotlib/testgraphplot.py +++ b/holoviews/tests/plotting/matplotlib/testgraphplot.py @@ -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()]) @@ -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): @@ -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): @@ -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)] @@ -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()]) @@ -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) @@ -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): @@ -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): @@ -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)) diff --git a/holoviews/tests/plotting/matplotlib/testpointplot.py b/holoviews/tests/plotting/matplotlib/testpointplot.py index e82fc54db2..95a2ea4b90 100644 --- a/holoviews/tests/plotting/matplotlib/testpointplot.py +++ b/holoviews/tests/plotting/matplotlib/testpointplot.py @@ -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): @@ -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):