From 19a1f4c82ea2f1de05da6ed929e96bacd7969269 Mon Sep 17 00:00:00 2001 From: michaelbabyn Date: Thu, 22 Nov 2018 10:26:38 -0500 Subject: [PATCH 1/2] update streamline for plotly v3 --- .../streamline/2015-06-30-streamline.html | 57 ++++++++----------- .../scientific/streamline/streamline.ipynb | 28 +++------ 2 files changed, 34 insertions(+), 51 deletions(-) diff --git a/_posts/python/scientific/streamline/2015-06-30-streamline.html b/_posts/python/scientific/streamline/2015-06-30-streamline.html index 4d6d44dd9ec1..d0dacb924264 100644 --- a/_posts/python/scientific/streamline/2015-06-30-streamline.html +++ b/_posts/python/scientific/streamline/2015-06-30-streamline.html @@ -10,12 +10,12 @@ title: Python Streamline Plots | plotly display_as: scientific has_thumbnail: true -order: 13 ipynb: ~notebook_demo/43 +order: 13 +page_type: u-guide --- {% raw %} -
-
+
@@ -32,7 +32,7 @@

Version CheckIn [1]:

-
-
+
-
import plotly.plotly as py
-import plotly.figure_factory as ff
+
-
-
-
-
+
- -
-
+
@@ -209,7 +200,7 @@

Reference<
In [4]:
-
help(ff.create_streamline)
+
help(ff.create_streamline)
 
@@ -221,8 +212,10 @@

Reference<
+
+
Help on function create_streamline in module plotly.figure_factory._streamline:
 
diff --git a/_posts/python/scientific/streamline/streamline.ipynb b/_posts/python/scientific/streamline/streamline.ipynb
index b7a687adf7ae..80c801f719d8 100644
--- a/_posts/python/scientific/streamline/streamline.ipynb
+++ b/_posts/python/scientific/streamline/streamline.ipynb
@@ -27,7 +27,7 @@
     {
      "data": {
       "text/plain": [
-       "'2.0.2'"
+       "'3.4.1'"
       ]
      },
      "execution_count": 1,
@@ -59,16 +59,6 @@
     "editable": true
    },
    "outputs": [
-    {
-     "name": "stderr",
-     "output_type": "stream",
-     "text": [
-      "/usr/local/lib/python2.7/site-packages/plotly/figure_factory/_streamline.py:357: RuntimeWarning:\n",
-      "\n",
-      "invalid value encountered in divide\n",
-      "\n"
-     ]
-    },
     {
      "data": {
       "text/html": [
@@ -162,11 +152,11 @@
     "# Add source point\n",
     "source_point = go.Scatter(x=[x_source], y=[y_source],\n",
     "                          mode='markers',\n",
-    "                          marker=go.Marker(size=14),\n",
+    "                          marker=go.scatter.Marker(size=14),\n",
     "                          name='source point')\n",
     "\n",
     "# Add source point to figure\n",
-    "fig['data'].append(source_point)\n",
+    "fig.add_trace(source_point)\n",
     "py.iplot(fig, filename='streamline_source')"
    ]
   },
@@ -348,23 +338,23 @@
  "metadata": {
   "anaconda-cloud": {},
   "kernelspec": {
-   "display_name": "Python 2",
+   "display_name": "Python 3",
    "language": "python",
-   "name": "python2"
+   "name": "python3"
   },
   "language_info": {
    "codemirror_mode": {
     "name": "ipython",
-    "version": 2
+    "version": 3
    },
    "file_extension": ".py",
    "mimetype": "text/x-python",
    "name": "python",
    "nbconvert_exporter": "python",
-   "pygments_lexer": "ipython2",
-   "version": "2.7.12"
+   "pygments_lexer": "ipython3",
+   "version": "3.6.5"
   }
  },
  "nbformat": 4,
- "nbformat_minor": 0
+ "nbformat_minor": 2
 }

From 6c4b3cd3800305b17d98b2d69aa5b1e8a745620c Mon Sep 17 00:00:00 2001
From: michaelbabyn 
Date: Thu, 22 Nov 2018 11:02:35 -0500
Subject: [PATCH 2/2] update quiver example for plotly 3.0

---
 .../scientific/quiver/2015-06-30-quiver.html  |  65 +++++++---
 _posts/python/scientific/quiver/quiver.ipynb  | 117 +++++++++---------
 2 files changed, 105 insertions(+), 77 deletions(-)

diff --git a/_posts/python/scientific/quiver/2015-06-30-quiver.html b/_posts/python/scientific/quiver/2015-06-30-quiver.html
index a38c3738b7d7..42219777db75 100644
--- a/_posts/python/scientific/quiver/2015-06-30-quiver.html
+++ b/_posts/python/scientific/quiver/2015-06-30-quiver.html
@@ -10,12 +10,12 @@
 title: Python Quiver Plots | plotly
 display_as: scientific
 has_thumbnail: true
-order: 12
 ipynb: ~notebook_demo/42
+order: 12
+page_type: u-guide
 ---
 {% raw %}
-
-
+
-
-
+
@@ -95,9 +96,11 @@

Basic Quiver Plot +
Out[2]:
+
@@ -108,8 +111,7 @@

Basic Quiver Plot -
+
@@ -119,7 +121,7 @@

Quiver Plot with Points
-
In [2]:
+
In [3]:
-
-
+
-
In [3]:
+
In [4]:
help(ff.create_quiver)
@@ -200,12 +203,14 @@ 

Reference<
+
+
Help on function create_quiver in module plotly.figure_factory._quiver:
 
-create_quiver(x, y, u, v, scale=0.1, arrow_scale=0.3, angle=0.3490658503988659, **kwargs)
+create_quiver(x, y, u, v, scale=0.1, arrow_scale=0.3, angle=0.3490658503988659, scaleratio=None, **kwargs)
     Returns data for a quiver plot.
     
     :param (list|ndarray) x: x coordinates of the arrow locations
@@ -217,6 +222,9 @@ 

Reference< :param (float in [0,1]) arrow_scale: value multiplied to length of barb to get length of arrowhead. Default = .3 :param (angle in radians) angle: angle of arrowhead. Default = pi/9 + :param (positive float) scaleratio: the ratio between the scale of the y-axis + and the scale of the x-axis (scale_y / scale_x). Default = None, the + scale ratio is not fixed. :param kwargs: kwargs passed through plotly.graph_objs.Scatter for more information on valid kwargs call help(plotly.graph_objs.Scatter) @@ -271,7 +279,7 @@

Reference< # Create quiver fig = create_quiver(x, y, u, v, scale=.2, arrow_scale=.3, angle=math.pi/6, - name='Wind Velocity', line=Line(width=1)) + name='Wind Velocity', line=dict(width=1)) # Add title to layout fig['layout'].update(title='Quiver Plot') @@ -279,6 +287,29 @@

Reference< # Plot py.plot(fig, filename='quiver') ``` + + Example 4: Forcing a fix scale ratio to maintain the arrow length + ``` + import plotly.plotly as py + from plotly.figure_factory import create_quiver + + import numpy as np + + # Add data + x,y = np.meshgrid(np.arange(0.5, 3.5, .5), np.arange(0.5, 4.5, .5)) + u = x + v = y + angle = np.arctan(v / u) + norm = 0.25 + u = norm * np.cos(angle) + v = norm * np.sin(angle) + + # Create quiver with a fix scale ratio + fig = create_quiver(x, y, u, v, scale = 1, scaleratio = 0.5) + + # Plot + py.plot(fig, filename='quiver') + ```

diff --git a/_posts/python/scientific/quiver/quiver.ipynb b/_posts/python/scientific/quiver/quiver.ipynb index 9c27bc985896..893800bd0e00 100644 --- a/_posts/python/scientific/quiver/quiver.ipynb +++ b/_posts/python/scientific/quiver/quiver.ipynb @@ -2,10 +2,7 @@ "cells": [ { "cell_type": "markdown", - "metadata": { - "deletable": true, - "editable": true - }, + "metadata": {}, "source": [ "#### New to Plotly?\n", "Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).\n", @@ -18,16 +15,12 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'2.0.2'" + "'3.4.1'" ] }, "execution_count": 1, @@ -42,10 +35,7 @@ }, { "cell_type": "markdown", - "metadata": { - "deletable": true, - "editable": true - }, + "metadata": {}, "source": [ "#### Basic Quiver Plot" ] @@ -53,11 +43,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, + "metadata": {}, "outputs": [ { "data": { @@ -89,10 +75,7 @@ }, { "cell_type": "markdown", - "metadata": { - "deletable": true, - "editable": true - }, + "metadata": {}, "source": [ "#### Quiver Plot with Points" ] @@ -100,11 +83,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, + "metadata": {}, "outputs": [ { "data": { @@ -146,17 +125,14 @@ " name='points')\n", "\n", "# Add points to figure\n", - "fig['data'].append(points)\n", + "fig.add_trace(points)\n", "\n", "py.iplot(fig, filename='Quiver with Points')" ] }, { "cell_type": "markdown", - "metadata": { - "deletable": true, - "editable": true - }, + "metadata": {}, "source": [ "#### Reference " ] @@ -164,11 +140,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -176,7 +148,7 @@ "text": [ "Help on function create_quiver in module plotly.figure_factory._quiver:\n", "\n", - "create_quiver(x, y, u, v, scale=0.1, arrow_scale=0.3, angle=0.3490658503988659, **kwargs)\n", + "create_quiver(x, y, u, v, scale=0.1, arrow_scale=0.3, angle=0.3490658503988659, scaleratio=None, **kwargs)\n", " Returns data for a quiver plot.\n", " \n", " :param (list|ndarray) x: x coordinates of the arrow locations\n", @@ -188,6 +160,9 @@ " :param (float in [0,1]) arrow_scale: value multiplied to length of barb\n", " to get length of arrowhead. Default = .3\n", " :param (angle in radians) angle: angle of arrowhead. Default = pi/9\n", + " :param (positive float) scaleratio: the ratio between the scale of the y-axis\n", + " and the scale of the x-axis (scale_y / scale_x). Default = None, the\n", + " scale ratio is not fixed.\n", " :param kwargs: kwargs passed through plotly.graph_objs.Scatter\n", " for more information on valid kwargs call\n", " help(plotly.graph_objs.Scatter)\n", @@ -242,7 +217,7 @@ " \n", " # Create quiver\n", " fig = create_quiver(x, y, u, v, scale=.2, arrow_scale=.3, angle=math.pi/6,\n", - " name='Wind Velocity', line=Line(width=1))\n", + " name='Wind Velocity', line=dict(width=1))\n", " \n", " # Add title to layout\n", " fig['layout'].update(title='Quiver Plot')\n", @@ -250,6 +225,29 @@ " # Plot\n", " py.plot(fig, filename='quiver')\n", " ```\n", + " \n", + " Example 4: Forcing a fix scale ratio to maintain the arrow length\n", + " ```\n", + " import plotly.plotly as py\n", + " from plotly.figure_factory import create_quiver\n", + " \n", + " import numpy as np\n", + " \n", + " # Add data\n", + " x,y = np.meshgrid(np.arange(0.5, 3.5, .5), np.arange(0.5, 4.5, .5))\n", + " u = x\n", + " v = y\n", + " angle = np.arctan(v / u)\n", + " norm = 0.25\n", + " u = norm * np.cos(angle)\n", + " v = norm * np.sin(angle)\n", + " \n", + " # Create quiver with a fix scale ratio\n", + " fig = create_quiver(x, y, u, v, scale = 1, scaleratio = 0.5)\n", + " \n", + " # Plot\n", + " py.plot(fig, filename='quiver')\n", + " ```\n", "\n" ] } @@ -260,12 +258,8 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false, - "deletable": true, - "editable": true - }, + "execution_count": 1, + "metadata": {}, "outputs": [ { "data": { @@ -292,17 +286,22 @@ "output_type": "display_data" }, { - "name": "stderr", + "name": "stdout", "output_type": "stream", "text": [ - "/usr/local/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning:\n", - "\n", - "The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead.\n", - "\n", - "/usr/local/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning:\n", - "\n", - "Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", - "\n" + "Collecting git+https://github.com/plotly/publisher.git\n", + " Cloning https://github.com/plotly/publisher.git to /tmp/pip-req-build-_Duvic\n", + "Building wheels for collected packages: publisher\n", + " Running setup.py bdist_wheel for publisher ... \u001b[?25ldone\n", + "\u001b[?25h Stored in directory: /tmp/pip-ephem-wheel-cache-RODQO4/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + "Successfully built publisher\n", + "Installing collected packages: publisher\n", + " Found existing installation: publisher 0.11\n", + " Uninstalling publisher-0.11:\n", + " Successfully uninstalled publisher-0.11\n", + "Successfully installed publisher-0.11\n", + "\u001b[33mYou are using pip version 10.0.1, however version 18.1 is available.\n", + "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n" ] } ], @@ -329,9 +328,7 @@ "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": true, - "deletable": true, - "editable": true + "collapsed": true }, "outputs": [], "source": [] @@ -353,9 +350,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.12" + "version": "2.7.15rc1" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 2 }