From d21c1d72a822ad276280e88bedb3ed69bc757a7c Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 11 Dec 2018 01:14:27 +0000 Subject: [PATCH] Updates to matplotlib element references to use opts (#3270) --- .../reference/elements/matplotlib/Arrow.ipynb | 7 +++-- .../reference/elements/matplotlib/Bars.ipynb | 8 +++--- .../elements/matplotlib/Bivariate.ipynb | 8 +++--- .../elements/matplotlib/Bounds.ipynb | 4 +-- .../reference/elements/matplotlib/Box.ipynb | 14 +++++++--- .../elements/matplotlib/BoxWhisker.ipynb | 9 ++++--- .../reference/elements/matplotlib/Chord.ipynb | 8 +++--- .../elements/matplotlib/Contours.ipynb | 5 ++-- .../reference/elements/matplotlib/Curve.ipynb | 8 +++--- .../elements/matplotlib/Distribution.ipynb | 3 +-- .../elements/matplotlib/Ellipse.ipynb | 6 +++-- .../reference/elements/matplotlib/Graph.ipynb | 13 +++++----- .../reference/elements/matplotlib/HLine.ipynb | 9 +++++-- .../reference/elements/matplotlib/HSV.ipynb | 5 +++- .../elements/matplotlib/HeatMap.ipynb | 7 ++--- .../elements/matplotlib/HexTiles.ipynb | 19 +++++++++----- .../elements/matplotlib/Histogram.ipynb | 6 +++-- .../reference/elements/matplotlib/Image.ipynb | 6 +++-- .../elements/matplotlib/Labels.ipynb | 17 ++++++------ .../elements/matplotlib/Points.ipynb | 20 +++++++------- .../elements/matplotlib/Polygons.ipynb | 10 +++---- .../elements/matplotlib/QuadMesh.ipynb | 5 ++-- .../reference/elements/matplotlib/RGB.ipynb | 6 +++-- .../elements/matplotlib/RadialHeatMap.ipynb | 13 +++++----- .../elements/matplotlib/Sankey.ipynb | 15 +++++------ .../elements/matplotlib/Spikes.ipynb | 26 +++++++++++-------- .../elements/matplotlib/Spline.ipynb | 9 +++++-- .../elements/matplotlib/Spread.ipynb | 7 ++--- .../elements/matplotlib/Surface.ipynb | 18 +++++++++---- .../reference/elements/matplotlib/Text.ipynb | 6 +++-- .../elements/matplotlib/TriMesh.ipynb | 6 +++-- .../elements/matplotlib/TriSurface.ipynb | 8 +++--- .../reference/elements/matplotlib/VLine.ipynb | 9 +++++-- .../elements/matplotlib/VectorField.ipynb | 20 +++++++++----- .../elements/matplotlib/Violin.ipynb | 9 ++++--- holoviews/plotting/mpl/annotation.py | 6 ++++- .../tests/plotting/matplotlib/testlabels.py | 15 +++++++---- 37 files changed, 228 insertions(+), 142 deletions(-) diff --git a/examples/reference/elements/matplotlib/Arrow.ipynb b/examples/reference/elements/matplotlib/Arrow.ipynb index fc857d79a5..32ce7aeb44 100644 --- a/examples/reference/elements/matplotlib/Arrow.ipynb +++ b/examples/reference/elements/matplotlib/Arrow.ipynb @@ -37,10 +37,13 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Curve (color='#D3D3D3')\n", "xs = np.linspace(-5,5,100)\n", "ys = -(xs-2)**3\n", - "hv.Curve((xs,ys)) * hv.Arrow(0, 5, 'Inflection', 'v')" + "\n", + "curve = hv.Curve((xs,ys))\n", + "arrow = hv.Arrow(0, 5, 'Inflection', 'v')\n", + "\n", + "curve.opts(color='#D3D3D3') * arrow" ] }, { diff --git a/examples/reference/elements/matplotlib/Bars.ipynb b/examples/reference/elements/matplotlib/Bars.ipynb index cc7f3fd91b..021473fd4d 100644 --- a/examples/reference/elements/matplotlib/Bars.ipynb +++ b/examples/reference/elements/matplotlib/Bars.ipynb @@ -73,15 +73,17 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Bars.Grouped [category_index=0 group_index=1 stack_index=5] \n", - "%%opts Bars.Stacked [color_by=['stack'] stack_index=1 category_index=5]\n", "from itertools import product\n", "np.random.seed(3)\n", "index, groups = ['A', 'B'], ['a', 'b']\n", "keys = product(index, groups)\n", "bars = hv.Bars([k+(np.random.rand()*100.,) for k in keys],\n", " ['Index', 'Group'], 'Count')\n", - "bars.relabel(group='Grouped') + bars.relabel(group='Stacked')" + "\n", + "grouped = bars.relabel('Grouped').opts(category_index=5, color_by=['stack'], stack_index=1)\n", + "stacked = bars.relabel('Stacked').opts(stack_index=5)\n", + "\n", + "grouped + stacked" ] }, { diff --git a/examples/reference/elements/matplotlib/Bivariate.ipynb b/examples/reference/elements/matplotlib/Bivariate.ipynb index 4f2f6804b1..dfe0578edd 100644 --- a/examples/reference/elements/matplotlib/Bivariate.ipynb +++ b/examples/reference/elements/matplotlib/Bivariate.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -58,8 +60,7 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Bivariate [filled=True colorbar=True] (cmap='Blues')\n", - "hv.Bivariate(normal)" + "hv.Bivariate(normal).opts(colorbar=True, cmap='Blues', filled=True)" ] }, { @@ -75,8 +76,7 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Bivariate {+axiswise}\n", - "hv.NdLayout({bw: hv.Bivariate(normal).options(bandwidth=bw)\n", + "hv.NdLayout({bw: hv.Bivariate(normal).options(axiswise=True, bandwidth=bw)\n", " for bw in [0.05, 0.1, 0.5, 1]}, 'Bandwidth')" ] }, diff --git a/examples/reference/elements/matplotlib/Bounds.ipynb b/examples/reference/elements/matplotlib/Bounds.ipynb index 25e834af88..1857ae7db5 100644 --- a/examples/reference/elements/matplotlib/Bounds.ipynb +++ b/examples/reference/elements/matplotlib/Bounds.ipynb @@ -36,9 +36,9 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Bounds (color='orange' linewidth=6)\n", "penguins = hv.RGB.load_image('../assets/penguins.png')\n", - "penguins * hv.Bounds((-0.15, -0.4, 0.2, 0))" + "bounds = hv.Bounds((-0.15, -0.4, 0.2, 0))\n", + "penguins * bounds.opts(color='orange', linewidth=6)" ] }, { diff --git a/examples/reference/elements/matplotlib/Box.ipynb b/examples/reference/elements/matplotlib/Box.ipynb index 3add4f43eb..b0a42a8c30 100644 --- a/examples/reference/elements/matplotlib/Box.ipynb +++ b/examples/reference/elements/matplotlib/Box.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -37,11 +39,12 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Box (linewidth=5 color='red') Image (cmap='gray')\n", "data = np.sin(np.mgrid[0:100,0:100][1]/10.0)\n", "data[np.arange(40, 60), np.arange(20, 40)] = -1\n", "data[np.arange(40, 50), np.arange(70, 80)] = -3 \n", - "hv.Image(data) * hv.Box(-0.2, 0, 0.25 ) * hv.Box(-0, 0, (0.4,0.9) )" + "(hv.Image(data) * hv.Box(-0.2, 0, 0.25 ) * hv.Box(-0, 0, (0.4,0.9))).opts(\n", + " opts.Box(color='red', linewidth=5),\n", + " opts.Image(cmap='gray'))" ] }, { @@ -59,10 +62,13 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Box (linewidth=5 color='purple') Image (cmap='gray')\n", "data = np.sin(np.mgrid[0:100,0:100][1]/10.0)\n", "data[np.arange(30, 70), np.arange(30, 70)] = -3\n", - "hv.Image(data) * hv.Box(-0, 0, 0.25, aspect=3, orientation=-np.pi/4)" + "box = hv.Box(-0, 0, 0.25, aspect=3, orientation=-np.pi/4)\n", + "\n", + "(hv.Image(data) * box).opts(\n", + " opts.Box(color='purple', linewidth=5),\n", + " opts.Image(cmap='gray'))" ] }, { diff --git a/examples/reference/elements/matplotlib/BoxWhisker.ipynb b/examples/reference/elements/matplotlib/BoxWhisker.ipynb index a1308c8079..d42b69fcd2 100644 --- a/examples/reference/elements/matplotlib/BoxWhisker.ipynb +++ b/examples/reference/elements/matplotlib/BoxWhisker.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -62,10 +64,11 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts BoxWhisker [aspect=2 fig_size=200 show_legend=False] (whiskerprops={'color': 'gray'})\n", "groups = [chr(65+g) for g in np.random.randint(0, 3, 200)]\n", - "hv.BoxWhisker((groups, np.random.randint(0, 5, 200), np.random.randn(200)),\n", - " ['Group', 'Category'], 'Value').sort()" + "box = hv.BoxWhisker((groups, np.random.randint(0, 5, 200), np.random.randn(200)),\n", + " ['Group', 'Category'], 'Value').sort()\n", + "\n", + "box.opts(opts.BoxWhisker(aspect=2, fig_size=200, whiskerprops={'color': 'gray'}))" ] }, { diff --git a/examples/reference/elements/matplotlib/Chord.ipynb b/examples/reference/elements/matplotlib/Chord.ipynb index aa3924ff61..fb193b0290 100644 --- a/examples/reference/elements/matplotlib/Chord.ipynb +++ b/examples/reference/elements/matplotlib/Chord.ipynb @@ -23,10 +23,12 @@ "source": [ "import pandas as pd\n", "import holoviews as hv\n", + "\n", + "from holoviews import dim, opts\n", "from bokeh.sampledata.les_mis import data\n", "\n", "hv.extension('matplotlib')\n", - "%output size=200 fig='svg'" + "hv.output(fig='svg', size=200)" ] }, { @@ -96,8 +98,8 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Chord [labels='name'] (node_color=dim('index').astype(str) edge_color=dim('source').astype(str) cmap='Category20' edge_cmap='Category20')\n", - "hv.Chord((links, nodes)).select(value=(5, None))" + "hv.Chord((links, nodes)).select(value=(5, None)).opts(\n", + " opts.Chord(cmap='Category20', edge_color=dim('source').astype(str), labels='name', node_color=dim('index').astype(str)))" ] } ], diff --git a/examples/reference/elements/matplotlib/Contours.ipynb b/examples/reference/elements/matplotlib/Contours.ipynb index 3cedf8afa8..cc728d23c5 100644 --- a/examples/reference/elements/matplotlib/Contours.ipynb +++ b/examples/reference/elements/matplotlib/Contours.ipynb @@ -60,12 +60,11 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Contours [colorbar=True] (cmap='fire')\n", "x,y = np.mgrid[-50:51, -50:51] * 0.05\n", "img = hv.Image(np.sin(x**2+y**3))\n", + "contours = hv.operation.contours(img, levels=5)\n", "\n", - "z0, z1 = img.range('z')\n", - "img + hv.operation.contours(img, levels=5)" + "img + contours.opts(colorbar=True, cmap='fire')" ] }, { diff --git a/examples/reference/elements/matplotlib/Curve.ipynb b/examples/reference/elements/matplotlib/Curve.ipynb index 1d6016862e..6486bdc3ad 100644 --- a/examples/reference/elements/matplotlib/Curve.ipynb +++ b/examples/reference/elements/matplotlib/Curve.ipynb @@ -70,9 +70,11 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts NdOverlay [legend_position='right']\n", - "hv.NdOverlay({interp: hv.Curve(points[::8]).options(interpolation=interp)\n", - " for interp in ['linear', 'steps-mid', 'steps-pre', 'steps-post']})" + "overlay = hv.NdOverlay({\n", + " interp: hv.Curve(points[::8]).options(interpolation=interp)\n", + " for interp in ['linear', 'steps-mid', 'steps-pre', 'steps-post']})\n", + "\n", + "overlay.opts(legend_position='right')" ] }, { diff --git a/examples/reference/elements/matplotlib/Distribution.ipynb b/examples/reference/elements/matplotlib/Distribution.ipynb index e9c82442b8..ddfb9d5922 100644 --- a/examples/reference/elements/matplotlib/Distribution.ipynb +++ b/examples/reference/elements/matplotlib/Distribution.ipynb @@ -62,8 +62,7 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Distribution [filled=False] (alpha=1)\n", - "hv.NdOverlay({bw: hv.Distribution(normal).options(bandwidth=bw)\n", + "hv.NdOverlay({bw: hv.Distribution(normal).opts(alpha=1, bandwidth=bw, filled=False)\n", " for bw in [0.05, 0.1, 0.5, 1]}, 'Bandwidth')" ] }, diff --git a/examples/reference/elements/matplotlib/Ellipse.ipynb b/examples/reference/elements/matplotlib/Ellipse.ipynb index cf91d51a08..37f26c388c 100644 --- a/examples/reference/elements/matplotlib/Ellipse.ipynb +++ b/examples/reference/elements/matplotlib/Ellipse.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -37,7 +39,8 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Ellipse (linewidth=6)\n", + "opts.defaults(opts.Ellipse(linewidth=6))\n", + "\n", "# Generate some data\n", "c1 = np.random.normal(loc=2, scale=0.2, size=(200,200))\n", "c2x = np.random.normal(loc=-2, scale=0.6, size=200)\n", @@ -61,7 +64,6 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Ellipse (linewidth=6)\n", "clusters = hv.Points(c1) * hv.Points((c2x, c2y)) * hv.Points(c3)\n", "clusters * hv.Ellipse(0,0, 4, orientation=np.pi/5, aspect=2) " ] diff --git a/examples/reference/elements/matplotlib/Graph.ipynb b/examples/reference/elements/matplotlib/Graph.ipynb index 76dadf13d8..1300f643c0 100644 --- a/examples/reference/elements/matplotlib/Graph.ipynb +++ b/examples/reference/elements/matplotlib/Graph.ipynb @@ -23,6 +23,7 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", "\n", "hv.extension('matplotlib')" ] @@ -60,8 +61,8 @@ "\n", "padding = dict(x=(-1.2, 1.2), y=(-1.2, 1.2))\n", "\n", - "simple_graph = hv.Graph(((source, target),)).options(padding=0.1)\n", - "simple_graph" + "simple_graph = hv.Graph(((source, target),))\n", + "simple_graph.opts(padding=0.1)" ] }, { @@ -79,7 +80,7 @@ "metadata": {}, "outputs": [], "source": [ - "simple_graph.options(directed=True, arrowhead_length=0.08)" + "simple_graph.opts(directed=True, arrowhead_length=0.08)" ] }, { @@ -107,7 +108,7 @@ "#### Additional features\n", "\n", "\n", - "Next we will extend this example by supplying explicit edges, node information and edge weights. By constructing the ``Nodes`` explicitly we can declare an additional value dimensions, which are revealed when hovering and/or can be mapped to the color by specifying the ``color_index``. We can also associate additional information with each edge by supplying a value dimension to the ``Graph`` itself, which we can map to a color using the ``edge_color_index``." + "Next we will extend this example by supplying explicit edges, node information and edge weights. By constructing the ``Nodes`` explicitly we can declare an additional value dimensions, which are revealed when hovering and/or can be mapped to the color by specifying the ``color``. We can also associate additional information with each edge by supplying a value dimension to the ``Graph`` itself, which we can map to a color using the ``edge_color``." ] }, { @@ -135,8 +136,8 @@ "nodes = hv.Nodes((x, y, node_indices, node_labels), vdims='Type')\n", "graph = hv.Graph(((source, target, edge_weights), nodes, paths), vdims='Weight')\n", "\n", - "graph.redim.range(**padding).options(color_index='Type', edge_color_index='Weight',\n", - " cmap=['blue', 'red'], edge_cmap='viridis')" + "graph.opts(\n", + " opts.Graph(cmap=['blue', 'red'], edge_cmap='viridis', edge_color='Weight', node_color='Type', padding=0.1))" ] }, { diff --git a/examples/reference/elements/matplotlib/HLine.ipynb b/examples/reference/elements/matplotlib/HLine.ipynb index bbd7f102c6..ef7b40b2f1 100644 --- a/examples/reference/elements/matplotlib/HLine.ipynb +++ b/examples/reference/elements/matplotlib/HLine.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -37,10 +39,13 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts HLine (color='blue' linewidth=6) Points (color='#D3D3D3')\n", "xs = np.random.normal(size=100)\n", "ys = np.random.normal(size=100) * xs\n", - "hv.Points((xs,ys)) * hv.HLine(ys.mean())" + "points = hv.Points((xs,ys))\n", + "\n", + "(points * hv.HLine(ys.mean())).opts(\n", + " opts.HLine(color='#D3D3D3')\n", + " opts.Points(color='blue', linewidth=6))" ] }, { diff --git a/examples/reference/elements/matplotlib/HSV.ipynb b/examples/reference/elements/matplotlib/HSV.ipynb index 932ba1b31e..f071af0ced 100644 --- a/examples/reference/elements/matplotlib/HSV.ipynb +++ b/examples/reference/elements/matplotlib/HSV.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -67,7 +69,8 @@ "metadata": {}, "outputs": [], "source": [ - "%opts Image (cmap='gray')\n", + "opts.defaults(opts.Image(cmap='gray'))\n", + "\n", "hsv[..., 'H'].relabel('H') + hsv[..., 'S'].relabel('S') + hsv[..., 'V'].relabel('V')" ] }, diff --git a/examples/reference/elements/matplotlib/HeatMap.ipynb b/examples/reference/elements/matplotlib/HeatMap.ipynb index 01b3272efd..e78226c1c3 100644 --- a/examples/reference/elements/matplotlib/HeatMap.ipynb +++ b/examples/reference/elements/matplotlib/HeatMap.ipynb @@ -75,9 +75,10 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts HeatMap [ colorbar=True fig_size=250]\n", - "hv.HeatMap((np.random.randint(0, 10, 100), np.random.randint(0, 10, 100),\n", - " np.random.randn(100), np.random.randn(100)), vdims=['z', 'z2']).redim.range(z=(-2, 2))" + "heatmap = hv.HeatMap((np.random.randint(0, 10, 100), np.random.randint(0, 10, 100),\n", + " np.random.randn(100), np.random.randn(100)), vdims=['z', 'z2']).redim.range(z=(-2, 2))\n", + "\n", + "heatmap.opts(colorbar=True, fig_size=250)" ] }, { diff --git a/examples/reference/elements/matplotlib/HexTiles.ipynb b/examples/reference/elements/matplotlib/HexTiles.ipynb index 3a311120a3..7575735dac 100644 --- a/examples/reference/elements/matplotlib/HexTiles.ipynb +++ b/examples/reference/elements/matplotlib/HexTiles.ipynb @@ -19,8 +19,10 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')\n", - "%output fig='svg' size=200" + "hv.output(fig='svg', size=200)" ] }, { @@ -40,7 +42,7 @@ "source": [ "np.random.seed(44)\n", "hex_tiles = hv.HexTiles(np.random.randn(100000, 2))\n", - "hex_tiles.options(colorbar=True)" + "hex_tiles.opts(colorbar=True)" ] }, { @@ -60,9 +62,11 @@ "source": [ "xs, ys = np.random.randn(2, 1000)\n", "hex_with_values = hv.HexTiles((xs, ys, xs*(ys/2.), (xs**2)*ys), vdims=['Values', 'Hover Values'])\n", + "points = hv.Points(hex_with_values)\n", "\n", - "hex_with_values.options(aggregator=np.sum) *\\\n", - "hv.Points(hex_with_values).options(s=3, color='black')" + "(hex_with_values * points).opts(\n", + " opts.HexTiles(aggregator=np.sum),\n", + " opts.Points(s=3, color='black'))" ] }, { @@ -82,8 +86,11 @@ "source": [ "x, y = np.hstack([np.random.randn(2, 10000), np.random.randn(2, 10000)*0.8+2])\n", "hex_two_distributions = hv.HexTiles((x, y))\n", - "hex_two_distributions.options(min_count=0) *\\\n", - "hv.Bivariate(hex_two_distributions).options(show_legend=False, linewidth=3)" + "bivariate = hv.Bivariate((x, y))\n", + "\n", + "(hex_two_distributions * bivariate).opts(\n", + " opts.Bivariate(linewidth=3, show_legend=False),\n", + " opts.HexTiles(min_count=0))" ] } ], diff --git a/examples/reference/elements/matplotlib/Histogram.ipynb b/examples/reference/elements/matplotlib/Histogram.ipynb index 365864537e..16c1607967 100644 --- a/examples/reference/elements/matplotlib/Histogram.ipynb +++ b/examples/reference/elements/matplotlib/Histogram.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -110,14 +112,14 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Histogram (alpha=0.3)\n", "from holoviews.operation import histogram\n", "points2 = hv.Points(np.random.randn(100,2)*2+1).redim.range(x=(-5, 5), y=(-5, 5))\n", "\n", "xhist, yhist = (histogram(points2, bin_range=(-5, 5), dimension=dim) *\n", " histogram(points, bin_range=(-5, 5), dimension=dim) \n", " for dim in 'xy')\n", - "(points2 * points) << yhist(plot=dict(width=125)) << xhist(plot=dict(height=125))" + "((points2 * points) << yhist << xhist).opts(\n", + " opts.Histogram(alpha=0.3))" ] }, { diff --git a/examples/reference/elements/matplotlib/Image.ipynb b/examples/reference/elements/matplotlib/Image.ipynb index d592f23955..6479792731 100644 --- a/examples/reference/elements/matplotlib/Image.ipynb +++ b/examples/reference/elements/matplotlib/Image.ipynb @@ -82,10 +82,12 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Points (color='black' marker='x' size=20)\n", "closest = img.closest((0.1,0.1))\n", + "points = hv.Points([closest])\n", + "\n", "print('The value at position %s is %s' % (closest, img[0.1, 0.1]))\n", - "img * hv.Points([img.closest((0.1,0.1))])" + "\n", + "img * points.opts(color='black', marker='x', s=60)" ] }, { diff --git a/examples/reference/elements/matplotlib/Labels.ipynb b/examples/reference/elements/matplotlib/Labels.ipynb index 068b00ce64..99f20f38dd 100644 --- a/examples/reference/elements/matplotlib/Labels.ipynb +++ b/examples/reference/elements/matplotlib/Labels.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -30,7 +32,7 @@ "source": [ "The ``Labels`` element may be used to annotate a plot with a number of labels. Unlike the ``Text`` element, ``Labels`` is vectorized and allows plotting many labels at once. It also supports any [tabular](../../../user_guide/07-Tabular_Datasets.ipynb) or [gridded](../../../user_guide/08-Gridded_Datasets.ipynb) data format. This also means that most other elements may be cast to a ``Labels`` element to annotate or label the values.\n", "\n", - "``Labels`` also support various options that make it convenient to use as an annotation, e.g. ``xoffset`` and ``yoffset`` options allow adjusting the position of the labels relative to an existing data point and the ``color_index`` option allows us to colormap the data by a certain dimension." + "``Labels`` also support various options that make it convenient to use as an annotation, e.g. ``xoffset`` and ``yoffset`` options allow adjusting the position of the labels relative to an existing data point and the ``color`` option allows us to colormap the data by a certain dimension." ] }, { @@ -42,11 +44,11 @@ "np.random.seed(9)\n", "data = np.random.rand(10, 2)\n", "points = hv.Points(data)\n", - "labels = hv.Labels({('x', 'y'): data, 'text': [chr(65+i) for i in range(10)]}, ['x', 'y'], 'text').options(\n", - " color_index='text', cmap='Category20', xoffset=0.05, yoffset=0.05, size=14\n", - ")\n", + "labels = hv.Labels({('x', 'y'): data, 'text': [chr(65+i) for i in range(10)]}, ['x', 'y'], 'text')\n", "\n", - "(points.options(color='black', s=25) * labels).redim.range(x=(-0.2, 1.2), y=(-.2, 1.2))" + "(points* labels).opts(\n", + " opts.Labels(color='text', cmap='Category20', xoffset=0.05, yoffset=0.05, size=14, padding=0.2),\n", + " opts.Points(color='black', s=25))" ] }, { @@ -68,9 +70,8 @@ "xs = ys = np.linspace(-2.5, 2.5, 25)\n", "zs = np.sin(xs**2)*np.sin(ys**2)[:, np.newaxis]\n", "\n", - "hv.Labels((xs, ys, zs), vdims=value_dimension).options(\n", - " bgcolor='black', cmap='viridis', color_index='Values', fig_size=200, size=8\n", - ").redim.range(x=(-2.6, 2.6), y=(-2.6, 2.6))" + "hv.Labels((xs, ys, zs), vdims=value_dimension).opts(\n", + " opts.Labels(bgcolor='black', cmap='viridis', color='Values', fig_size=200, padding=0.05, size=8))" ] } ], diff --git a/examples/reference/elements/matplotlib/Points.ipynb b/examples/reference/elements/matplotlib/Points.ipynb index 163735eb74..a76812c406 100644 --- a/examples/reference/elements/matplotlib/Points.ipynb +++ b/examples/reference/elements/matplotlib/Points.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import dim, opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -28,7 +30,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The ``Points`` element visualizes as markers placed in a space of two independent variables, traditionally denoted *x* and *y*. In HoloViews, the names ``'x'`` and ``'y'`` are used as the default ``key_dimensions`` of the element. We can see this from the default axis labels when visualizing a simple ``Points`` element:" + "The ``Points`` element visualizes as markers placed in a space of two independent variables, traditionally denoted ``x`` and ``y``. In HoloViews, the names ``'x'`` and ``'y'`` are used as the default key dimensions (``kdims``) of the element. We can see this from the default axis labels when visualizing a simple ``Points`` element:" ] }, { @@ -37,17 +39,18 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Points (color='k' marker='+' size=10)\n", "np.random.seed(12)\n", "coords = np.random.rand(50,2)\n", - "hv.Points(coords)" + "points = hv.Points(coords)\n", + "\n", + "points.opts(color='k', marker='+', s=50)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Here both the random *x* values and random *y* values are *both* considered to be the 'data' with no dependency between them (compare this to how [``Scatter``](./Scatter.ipynb) elements are defined). You can think of ``Points`` as simply marking positions in some two-dimensional space that can be sliced by specifying a 2D region-of-interest:" + "Here both the random ``x`` values and random ``y`` values are *both* considered to be the coordinates with no dependency between them (compare this to how [``Scatter``](./Scatter.ipynb) elements are defined). You can think of ``Points`` as simply marking positions in some two-dimensional space that can be sliced by specifying a 2D region-of-interest:" ] }, { @@ -56,15 +59,14 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Points (color='k' marker='+' size=10)\n", - "hv.Points(coords) + hv.Points(coords)[0.6:0.8,0.2:0.5]" + "points + points[0.6:0.8,0.2:0.5]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Although the simplest ``Points`` element simply mark positions in a two-dimensional space without any associated value this doesn't mean value dimensions aren't supported. Here is an example with two additional quantities for each point, declared as the ``value_dimension``s *z* and α visualized as the color and size of the dots, respectively:" + "Although the simplest ``Points`` element simply mark positions in a two-dimensional space without any associated value this doesn't mean value dimensions aren't supported. Here is an example with two additional quantities for each point, declared as the ``vdims``s ``z`` and ``size`` visualized as the color and size of the dots, respectively:" ] }, { @@ -73,12 +75,12 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Points [color_index=2 size_index=3 scaling_factor=50]\n", "np.random.seed(10)\n", "data = np.random.rand(100,4)\n", "\n", "points = hv.Points(data, vdims=['z', 'size'])\n", - "points + points[0.3:0.7, 0.3:0.7].hist()" + "(points + points[0.3:0.7, 0.3:0.7].hist()).opts(\n", + " opts.Points(color='z', s=dim('size')*50))" ] }, { diff --git a/examples/reference/elements/matplotlib/Polygons.ipynb b/examples/reference/elements/matplotlib/Polygons.ipynb index da9c13bbaf..4e618f0165 100644 --- a/examples/reference/elements/matplotlib/Polygons.ipynb +++ b/examples/reference/elements/matplotlib/Polygons.ipynb @@ -32,7 +32,7 @@ "\n", "In order to efficiently represent the scalar values associated with each path the dictionary format is preferable since it can store the scalar values without expanding them into a whole column. Additionally it allows passing multiple columns as a single array by specifying the dimension names as a tuple.\n", "\n", - "In this example we will create a list of random polygons each with an associated ``level`` value. Polygons will default to using the first value dimension as the ``color_index`` but for clarity we will define the ``color_index`` explicitly:" + "In this example we will create a list of random polygons each with an associated ``level`` value. Polygons will default to using the first value dimension as the ``color`` but for clarity we will define the ``color`` explicitly:" ] }, { @@ -41,13 +41,13 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Polygons [color_index='level'] (linewidth=1)\n", - "\n", "def rectangle(x=0, y=0, width=.05, height=.05):\n", " return np.array([(x,y), (x+width, y), (x+width, y+height), (x, y+height)])\n", "\n", - "hv.Polygons([{('x', 'y'): rectangle(x, y), 'level': z}\n", - " for x, y, z in np.random.rand(100, 3)], vdims='level').redim.range(x=(-.1,1.1), y=(-0.1, 1.1))" + "polys = hv.Polygons([{('x', 'y'): rectangle(x, y), 'level': z}\n", + " for x, y, z in np.random.rand(100, 3)], vdims='level')\n", + "\n", + "polys.opts(color='level', linewidth=1, padding=0.1)" ] }, { diff --git a/examples/reference/elements/matplotlib/QuadMesh.ipynb b/examples/reference/elements/matplotlib/QuadMesh.ipynb index cbb9291c88..8cc854b7d1 100644 --- a/examples/reference/elements/matplotlib/QuadMesh.ipynb +++ b/examples/reference/elements/matplotlib/QuadMesh.ipynb @@ -70,8 +70,9 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts QuadMesh [xticks=[10, 100,1000]] QuadMesh.LogScale [logx=True]\n", - "hv.QuadMesh((xs, ys, zs), group='LinearScale') + hv.QuadMesh((xs, ys, zs), group='LogScale')" + "qmesh = hv.QuadMesh((xs, ys, zs), label='Linear Axis')\n", + "log_qmesh = qmesh.relabel('Log x-axis')\n", + "qmesh + log_qmesh.opts(logx=True)" ] }, { diff --git a/examples/reference/elements/matplotlib/RGB.ipynb b/examples/reference/elements/matplotlib/RGB.ipynb index e3c42bf6eb..08f5e7dda1 100644 --- a/examples/reference/elements/matplotlib/RGB.ipynb +++ b/examples/reference/elements/matplotlib/RGB.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -92,7 +94,8 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Image (cmap='gray')\n", + "opts.defaults(opts.Image(cmap='gray'))\n", + "\n", "hv.Image(r,label=\"R\") + hv.Image(g,label=\"G\") + hv.Image(b,label=\"B\")" ] }, @@ -109,7 +112,6 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Image (cmap='gray')\n", "mask = 0.5*np.sin(0.2*(x**2+y**2))+0.5\n", "rgba = hv.RGB(np.dstack([r,g,b,mask]))\n", "\n", diff --git a/examples/reference/elements/matplotlib/RadialHeatMap.ipynb b/examples/reference/elements/matplotlib/RadialHeatMap.ipynb index 9920055fc2..53a5a4624b 100644 --- a/examples/reference/elements/matplotlib/RadialHeatMap.ipynb +++ b/examples/reference/elements/matplotlib/RadialHeatMap.ipynb @@ -22,10 +22,12 @@ "import numpy as np\n", "import pandas as pd\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')\n", "\n", - "%output fig='svg'\n", - "%opts HeatMap [fig_size=250]" + "hv.output(fig='svg')\n", + "opts.defaults(opts.HeatMap(fig_size=250))" ] }, { @@ -76,8 +78,7 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts HeatMap [radial=True]\n", - "hv.HeatMap(df, [\"hour\", \"day\"])" + "hv.HeatMap(df, [\"hour\", \"day\"]).opts(radial=True)" ] }, { @@ -98,8 +99,8 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts HeatMap [radial=True radius_inner=0.2 xmarks=8 xticks=8 ymarks=4] (cmap='viridis')\n", - "hv.HeatMap(df, [\"hour\", \"day\"])" + "hv.HeatMap(df, [\"hour\", \"day\"]).opts(\n", + " opts.HeatMap(cmap='viridis', radial=True, radius_inner=0.2, xmarks=8, xticks=8, ymarks=4))" ] } ], diff --git a/examples/reference/elements/matplotlib/Sankey.ipynb b/examples/reference/elements/matplotlib/Sankey.ipynb index f2b05e9f89..8ab08248f3 100644 --- a/examples/reference/elements/matplotlib/Sankey.ipynb +++ b/examples/reference/elements/matplotlib/Sankey.ipynb @@ -18,10 +18,10 @@ "outputs": [], "source": [ "import holoviews as hv\n", - "from holoviews import dim\n", - "hv.extension('matplotlib')\n", + "from holoviews import dim, opts\n", "\n", - "%output fig='svg'" + "hv.extension('matplotlib')\n", + "hv.output(fig='svg')" ] }, { @@ -46,7 +46,7 @@ " ('B', 'X', 2),\n", " ('B', 'Y', 9),\n", " ('B', 'Z', 4)]\n", - ").options(fig_size=200)" + ").opts(fig_size=200)" ] }, { @@ -72,10 +72,9 @@ "]\n", "\n", "value_dim = hv.Dimension('Percentage', unit='%')\n", - "hv.Sankey((edges, nodes), ['From', 'To'], vdims=value_dim).options(\n", - " labels='label', label_position='right', fig_size=300, edge_color=dim('To').str(),\n", - " node_color=dim('index').str(), cmap='Set1'\n", - ")" + "hv.Sankey((edges, nodes), ['From', 'To'], vdims=value_dim).opts(\n", + " opts.Sankey(cmap='Set1', labels='label', label_position='right', fig_size=300,\n", + " edge_color=dim('To').str(), node_color=dim('index').str()))" ] } ], diff --git a/examples/reference/elements/matplotlib/Spikes.ipynb b/examples/reference/elements/matplotlib/Spikes.ipynb index 28f48c7497..103a9a26f6 100644 --- a/examples/reference/elements/matplotlib/Spikes.ipynb +++ b/examples/reference/elements/matplotlib/Spikes.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -39,9 +41,8 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Spikes (alpha=0.4) [spike_length=0.1]\n", "xs = np.random.rand(50)\n", - "hv.Spikes(xs)" + "hv.Spikes(xs).opts(alpha=0.4, spike_length=0.1)" ] }, { @@ -57,9 +58,10 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Points (color='red')\n", "ys = np.random.rand(50)\n", - "hv.Points((xs, ys)) * hv.Spikes(xs)" + "points = hv.Points((xs, ys))\n", + "spikes = hv.Spikes(xs)\n", + "points.opts(color='red') * spikes" ] }, { @@ -75,8 +77,7 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Spikes (color='Intensity' cmap='Reds')\n", - "hv.Spikes(np.random.rand(20, 2), 'Mass', 'Intensity')" + "hv.Spikes(np.random.rand(20, 2), 'Mass', 'Intensity').opts(cmap='Reds', color='Intensity')" ] }, { @@ -92,9 +93,12 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Spikes [spike_length=0.1] NdOverlay [show_legend=False]\n", - "hv.NdOverlay({i: hv.Spikes(np.random.randint(0, 100, 10), 'Time').options(position=0.1*i)\n", - " for i in range(10)}).options(yticks=[((i+1)*0.1-0.05, i) for i in range(10)])" + "overlay = hv.NdOverlay({i: hv.Spikes(np.random.randint(0, 100, 10), 'Time').options(\n", + " position=0.1*i, spike_length=0.1) for i in range(10)})\n", + "\n", + "ticks = [((i+1)*0.1-0.05, i) for i in range(10)]\n", + "\n", + "overlay.opts(show_legend=False, yticks=ticks)" ] }, { @@ -110,9 +114,9 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Spikes (alpha=0.2)\n", "points = hv.Points(np.random.randn(500, 2))\n", - "points << hv.Spikes(points['y']) << hv.Spikes(points['x'])" + "(points << hv.Spikes(points['y']) << hv.Spikes(points['x'])).opts(\n", + " opts.Spikes(alpha=0.2))" ] }, { diff --git a/examples/reference/elements/matplotlib/Spline.ipynb b/examples/reference/elements/matplotlib/Spline.ipynb index dab3cf1b6d..14e5d003da 100644 --- a/examples/reference/elements/matplotlib/Spline.ipynb +++ b/examples/reference/elements/matplotlib/Spline.ipynb @@ -20,6 +20,8 @@ "outputs": [], "source": [ "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -36,9 +38,12 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Curve (color='#D3D3D3') Spline (linewidth=6 edgecolor='green')\n", "points = [(-0.3, -0.3), (0,0), (0.25, -0.25), (0.3, 0.3)]\n", - "hv.Spline((points, [1,4,4,4])) * hv.Curve(points)" + "spline = hv.Spline((points, [1,4,4,4]))\n", + "\n", + "(spline * hv.Curve(points)).opts(\n", + " opts.Curve(color='#D3D3D3')\n", + " opts.Spline(linewidth=6, edgecolor='green'))" ] }, { diff --git a/examples/reference/elements/matplotlib/Spread.ipynb b/examples/reference/elements/matplotlib/Spread.ipynb index 6da7cc0bf4..13ceb18572 100644 --- a/examples/reference/elements/matplotlib/Spread.ipynb +++ b/examples/reference/elements/matplotlib/Spread.ipynb @@ -74,10 +74,11 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Spread (facecolor='indianred' alpha=1)\n", "xs = np.linspace(0, np.pi*2, 20)\n", - "hv.Spread((xs, np.sin(xs), 0.1+np.random.rand(len(xs)), 0.1+np.random.rand(len(xs))),\n", - " vdims=['y', 'yerrneg', 'yerrpos'])" + "spread = hv.Spread((xs, np.sin(xs), 0.1+np.random.rand(len(xs)), 0.1+np.random.rand(len(xs))),\n", + " vdims=['y', 'yerrneg', 'yerrpos'])\n", + "\n", + "spread.opts(alpha=1, facecolor='indianred')" ] }, { diff --git a/examples/reference/elements/matplotlib/Surface.ipynb b/examples/reference/elements/matplotlib/Surface.ipynb index cd7de562c1..c797510f55 100644 --- a/examples/reference/elements/matplotlib/Surface.ipynb +++ b/examples/reference/elements/matplotlib/Surface.ipynb @@ -22,6 +22,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -40,8 +42,9 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Surface [azimuth=30 elevation=30] (cmap='plasma' rstride=20, cstride=2)\n", - "hv.Surface(np.sin(np.linspace(0,100*np.pi*2,10000)).reshape(100,100))" + "surface = hv.Surface(np.sin(np.linspace(0,100*np.pi*2,10000)).reshape(100,100))\n", + "\n", + "surface.opts(opts.Surface(azimuth=30, elevation=30, rstride=20, cstride=2, cmap='plasma'))" ] }, { @@ -57,14 +60,19 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Surface [azimuth=60] (cmap='fire' linewidth=1 edgecolor='black') Layout [fig_size=150 hspace=0.1]\n", "xs = np.arange(-4, 4, 0.25)\n", "ys = np.arange(-4, 4, 0.25)\n", "X, Y = np.meshgrid(xs, ys)\n", "R = np.sqrt(X**2 + Y**2)\n", "Z = np.sin(R)\n", - "surface = hv.Surface((xs, ys, Z))\n", - "surface + surface.options(plot_type='wireframe') + surface.options(plot_type='contour')" + "\n", + "surface = hv.Surface((xs, ys, Z), label='Surface')\n", + "wireframe = surface.relabel('Wireframe').opts(plot_type='wireframe')\n", + "contour = surface.relabel('Contour').opts(plot_type='contour')\n", + "\n", + "(surface + wireframe + contour).opts(\n", + " opts.Layout(fig_size=150, hspace=0.1),\n", + " opts.Surface(azimuth=60, cmap='fire'))" ] }, { diff --git a/examples/reference/elements/matplotlib/Text.ipynb b/examples/reference/elements/matplotlib/Text.ipynb index d90fbf4116..1fcd6dcd25 100644 --- a/examples/reference/elements/matplotlib/Text.ipynb +++ b/examples/reference/elements/matplotlib/Text.ipynb @@ -37,9 +37,11 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Curve (color='#D3D3D3')\n", "xs = np.linspace(-5,5,100)\n", - "hv.Curve((xs,-(xs-2)**2)) * hv.Text(0, -30, 'Quadratic Curve')" + "curve = hv.Curve((xs,-(xs-2)**2))\n", + "text = hv.Text(0, -30, 'Quadratic Curve')\n", + "\n", + "curve.opts(color='#D3D3D3') * text" ] }, { diff --git a/examples/reference/elements/matplotlib/TriMesh.ipynb b/examples/reference/elements/matplotlib/TriMesh.ipynb index 6eac8ff003..8435cd6a8f 100644 --- a/examples/reference/elements/matplotlib/TriMesh.ipynb +++ b/examples/reference/elements/matplotlib/TriMesh.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "\n", + "from holoviews import opts\n", "from scipy.spatial import Delaunay\n", "\n", "hv.extension('matplotlib')" @@ -150,8 +152,8 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts TriMesh [filled=True fig_size=200] (cmap='viridis' edge_color='z')\n", - "hv.TriMesh((simplices, hv.Points(nodes, vdims='z')))" + "hv.TriMesh((simplices, hv.Points(nodes, vdims='z'))).opts(\n", + " opts.TriMesh(cmap='viridis', edge_color='z', filled=True, fig_size=200))" ] }, { diff --git a/examples/reference/elements/matplotlib/TriSurface.ipynb b/examples/reference/elements/matplotlib/TriSurface.ipynb index 67f775b6c1..e68561732a 100644 --- a/examples/reference/elements/matplotlib/TriSurface.ipynb +++ b/examples/reference/elements/matplotlib/TriSurface.ipynb @@ -38,10 +38,10 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts TriSurface [azimuth=30 elevation=30 fig_size=200]\n", "y,x = np.mgrid[-5:5, -5:5] * 0.1\n", "heights = np.sin(x**2+y**2)\n", - "hv.TriSurface((x.flat,y.flat,heights.flat))" + "hv.TriSurface((x.flat,y.flat,heights.flat)).opts(\n", + " azimuth=30, elevation=30, fig_size=200)" ] }, { @@ -57,8 +57,6 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts TriSurface [fig_size=200 colorbar=True] (cmap='fire')\n", - "\n", "u=np.linspace(0,2*np.pi, 24)\n", "v=np.linspace(-1,1, 8)\n", "u,v=np.meshgrid(u,v)\n", @@ -72,7 +70,7 @@ "z=0.5*v*np.sin(u/2.)\n", "\n", "surface = hv.TriSurface((x, y, z), label='Moebius band')\n", - "surface" + "surface.opts(cmap='fire', colorbar=True, fig_size=200)" ] }, { diff --git a/examples/reference/elements/matplotlib/VLine.ipynb b/examples/reference/elements/matplotlib/VLine.ipynb index 9b37c9984b..a464e1e07c 100644 --- a/examples/reference/elements/matplotlib/VLine.ipynb +++ b/examples/reference/elements/matplotlib/VLine.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -37,10 +39,13 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts VLine (color='red' linewidth=6) Curve (color='#D3D3D3')\n", "xs = np.linspace(-5,5,100)\n", "ys = -(xs-2)**2\n", - "hv.Curve((xs,ys)) * hv.VLine(xs[ys.argmax()])" + "vline = hv.VLine(xs[ys.argmax()])\n", + "\n", + "(hv.Curve((xs,ys)) * vline).opts(\n", + " opts.Curve(color='#D3D3D3'),\n", + " opts.Vline(color='red', linewidth=6)" ] }, { diff --git a/examples/reference/elements/matplotlib/VectorField.ipynb b/examples/reference/elements/matplotlib/VectorField.ipynb index 44fe4d0863..8d2204aeeb 100644 --- a/examples/reference/elements/matplotlib/VectorField.ipynb +++ b/examples/reference/elements/matplotlib/VectorField.ipynb @@ -21,6 +21,8 @@ "source": [ "import numpy as np\n", "import holoviews as hv\n", + "from holoviews import dim, opts\n", + "\n", "hv.extension('matplotlib')" ] }, @@ -37,13 +39,12 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts VectorField [magnitude='Magnitude']\n", "x,y = np.mgrid[-10:10,-10:10] * 0.25\n", "sine_rings = np.sin(x**2+y**2)*np.pi+np.pi\n", "exp_falloff = 1/np.exp((x**2+y**2)/8)\n", "\n", "vector_data = (x, y, sine_rings, exp_falloff)\n", - "hv.VectorField(vector_data)" + "hv.VectorField(vector_data).opts(magnitude='Magnitude')" ] }, { @@ -78,9 +79,10 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts VectorField [magnitude=dim('Magnitude').norm()*0.2 rescale_lengths=False] (color='Angle')\n", - "hv.HoloMap({phase: hv.VectorField([x, y,(vector_data[2]+phase)%np.pi*2, vector_data[3]+np.abs(phase)])\n", - " for phase in np.linspace(-np.pi,np.pi,5)}, kdims='Phase')" + "hmap = hv.HoloMap({phase: hv.VectorField((x, y,(vector_data[2]+phase)%np.pi*2, vector_data[3]+np.abs(phase)))\n", + " for phase in np.linspace(-np.pi,np.pi,5)}, kdims='Phase')\n", + "\n", + "hmap.opts(opts.VectorField(color='Angle', magnitude=dim('Magnitude').norm()*0.2, rescale_lengths=False))" ] }, { @@ -119,8 +121,12 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts VectorField [magnitude='Magnitude' aspect=2 fig_size=300] (pivot='tip' cmap='fire' scale=0.8 color='Magnitude') Points (color='black' s=1)\n", - "hv.VectorField((xs, ys, angle, mag)) * hv.Points((X.flat, Y.flat))" + "vectors = hv.VectorField((xs, ys, angle, mag))\n", + "points = hv.Points((X.flat, Y.flat))\n", + "\n", + "(vectors * points).opts(\n", + " opts.Points(color='black', s=1),\n", + " opts.VectorField(aspect=2, color='Magnitude', cmap='fire', fig_size=300, magnitude='Magnitude', pivot='tip', scale=0.8))" ] }, { diff --git a/examples/reference/elements/matplotlib/Violin.ipynb b/examples/reference/elements/matplotlib/Violin.ipynb index 0558243f11..9450e4b84c 100644 --- a/examples/reference/elements/matplotlib/Violin.ipynb +++ b/examples/reference/elements/matplotlib/Violin.ipynb @@ -59,7 +59,7 @@ "metadata": {}, "outputs": [], "source": [ - "violin.relabel(group='Medians').options(inner='medians', cut=0.1, bandwidth=0.1)" + "violin.relabel(group='Medians').opts(inner='medians', bandwidth=0.1)" ] }, { @@ -75,10 +75,11 @@ "metadata": {}, "outputs": [], "source": [ - "%%opts Violin [fig_size=300 aspect=2.5 show_legend=False]\n", "groups = [chr(65+g) for g in np.random.randint(0, 3, 200)]\n", - "hv.Violin((groups, np.random.randint(0, 5, 200), np.random.randn(200)),\n", - " ['Group', 'Category'], 'Value')" + "violin = hv.Violin((groups, np.random.randint(0, 5, 200), np.random.randn(200)),\n", + " ['Group', 'Category'], 'Value')\n", + "\n", + "violin.opts(aspect=2.5, fig_size=300)" ] }, { diff --git a/holoviews/plotting/mpl/annotation.py b/holoviews/plotting/mpl/annotation.py index a1e2bbbaa2..6fe08be6fd 100644 --- a/holoviews/plotting/mpl/annotation.py +++ b/holoviews/plotting/mpl/annotation.py @@ -121,10 +121,14 @@ def get_data(self, element, ranges, style): if self.yoffset is not None: ys += self.yoffset + cs = None cdim = element.get_dimension(self.color_index) if cdim: self._norm_kwargs(element, ranges, style, cdim) - cs = element.dimension_values(cdim) if cdim else None + cs = element.dimension_values(cdim) + if 'c' in style: + cs = style.pop('c') + if 'size' in style: style['fontsize'] = style.pop('size') if 'horizontalalignment' not in style: style['horizontalalignment'] = 'center' if 'verticalalignment' not in style: style['verticalalignment'] = 'center' diff --git a/holoviews/tests/plotting/matplotlib/testlabels.py b/holoviews/tests/plotting/matplotlib/testlabels.py index 5da51f7915..8776c4ca5f 100644 --- a/holoviews/tests/plotting/matplotlib/testlabels.py +++ b/holoviews/tests/plotting/matplotlib/testlabels.py @@ -3,6 +3,7 @@ from holoviews.core.dimension import Dimension from holoviews.core.spaces import HoloMap from holoviews.element import Labels +from holoviews.plotting.util import rgb2hex from .testplot import TestMPLPlot, mpl_renderer @@ -92,14 +93,18 @@ def test_label_color_op_update(self): def test_label_linear_color_op(self): labels = Labels([(0, 0, 0), (0, 1, 1), (0, 2, 2)], vdims='color').options(color='color') - with self.assertRaises(Exception): - mpl_renderer.get_plot(labels) + plot = mpl_renderer.get_plot(labels) + artist = plot.handles['artist'] + self.assertEqual([rgb2hex(a.get_color()) for a in artist], + ['#440154', '#20908c', '#fde724']) def test_label_categorical_color_op(self): labels = Labels([(0, 0, 'A'), (0, 1, 'B'), (0, 2, 'A')], - vdims='color').options(color='color') - with self.assertRaises(Exception): - mpl_renderer.get_plot(labels) + vdims='color').options(color='color', cmap='tab10') + plot = mpl_renderer.get_plot(labels) + artist = plot.handles['artist'] + self.assertEqual([rgb2hex(a.get_color()) for a in artist], + ['#1f77b4', '#ff7f0e', '#1f77b4']) def test_label_size_op(self): labels = Labels([(0, 0, 8), (0, 1, 12), (0, 2, 6)],