From ac6ed652fe763885f5ff589a9997388b9adb337c Mon Sep 17 00:00:00 2001 From: Kully Date: Thu, 27 Sep 2018 10:33:11 -0400 Subject: [PATCH] projections 3d doc is python3 and plotly3 friendly --- ...-06-30-Plotly-project-3d-onto-a-plane.html | 85 ++++++++++--------- .../Plotly-project-3d-onto-a-plane.ipynb | 83 ++++++++---------- 2 files changed, 78 insertions(+), 90 deletions(-) diff --git a/_posts/python/3d/projection-of-3d-plots/2015-06-30-Plotly-project-3d-onto-a-plane.html b/_posts/python/3d/projection-of-3d-plots/2015-06-30-Plotly-project-3d-onto-a-plane.html index b61257b8f1a7..484f66f7e238 100644 --- a/_posts/python/3d/projection-of-3d-plots/2015-06-30-Plotly-project-3d-onto-a-plane.html +++ b/_posts/python/3d/projection-of-3d-plots/2015-06-30-Plotly-project-3d-onto-a-plane.html @@ -18,7 +18,7 @@
-

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer. +

New to Plotly?¶

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

@@ -29,7 +29,7 @@

New to Plotly?
-

Projections of a 3d surface onto planes

+

Projections of a 3d surface onto planes¶

@@ -58,7 +58,7 @@

Projections of a 3d surface ont
-
In [4]:
+
In [1]:
import plotly.plotly as py
@@ -81,13 +81,13 @@ 

Projections of a 3d surface ont

-

Color according to normalized z-values

+

Color according to normalized z-values¶

-
In [5]:
+
In [2]:
colorscale=[[0.0, 'rgb(20,29,67)'],
@@ -112,25 +112,26 @@ 

Color according to normalized z-

-

Add hover text for the surface:

+

Add hover text for the surface:¶

-
In [6]:
+
In [3]:
-
textz=[['x: '+'{:0.5f}'.format(x[i][j])+'<br>y: '+'{:0.5f}'.format(y[i][j])+
+
textz = [['x: '+'{:0.5f}'.format(x[i][j])+'<br>y: '+'{:0.5f}'.format(y[i][j])+
         '<br>z: '+'{:0.5f}'.format(z[i][j]) for j in range(z.shape[1])] for i in range(z.shape[0])]
 
-trace1= go.Surface(z=z,
-                x=x,
-                y=y,
-                colorscale=colorscale,
-                text=textz,
-                hoverinfo='text',
-                )
+trace1= go.Surface(
+    x=tuple(x),
+    y=tuple(y),
+    z=tuple(z),
+    colorscale=colorscale,
+    text=textz,
+    hoverinfo='text',
+)
 
@@ -142,24 +143,24 @@

Add hover text for the surface:
-

Set Plot Layout:

+

Set Plot Layout:¶

-
In [7]:
+
In [4]:
axis = dict(
-showbackground=True,
-backgroundcolor="rgb(230, 230,230)",
-showgrid=False,
-zeroline=False,
+showbackground=True, 
+backgroundcolor="rgb(230, 230,230)", 
+showgrid=False,    
+zeroline=False,  
 showline=False)
 
-ztickvals=range(-6,4)
-layout = go.Layout(title="Projections of a surface onto coordinate planes" ,
+ztickvals=list(range(-6,4))
+layout = go.Layout(title="Projections of a surface onto coordinate planes" , 
                 autosize=False,
                 width=700,
                 height=600,
@@ -182,7 +183,7 @@ 

Set Plot Layout:
-

Discretization of each Plane

The surface projections will be plotted in the planes of equations +

Discretization of each Plane¶

The surface projections will be plotted in the planes of equations Z=np.min(z)-2, X=np.min(xx), respectively Y=np.min(yy).

@@ -190,7 +191,7 @@

Discretization of each Plane
-
In [8]:
+
In [5]:
z_offset=(np.min(z)-2)*np.ones(z.shape)#
@@ -208,8 +209,8 @@ 

Discretization of each Plane

Define the color functions and the color numpy arrays, C_z, C_x, C_y, corresponding to each plane:
-Define the 3-tuples of coordinates to be displayed at hovering the mouse over the projections. -The first two coordinates give the position in the projection plane, whereas the third one is used +Define the 3-tuples of coordinates to be displayed at hovering the mouse over the projections. +The first two coordinates give the position in the projection plane, whereas the third one is used for assigning the color, just in the same way the coordinate z is used for the z-direction projection.

@@ -217,7 +218,7 @@

Discretization of each Plane
-
In [9]:
+
In [7]:
@@ -292,6 +293,6 @@

Discretization of each Planey: '+'{:0.5f}'.format(y[i][j])+\n", + "textz = [['x: '+'{:0.5f}'.format(x[i][j])+'
y: '+'{:0.5f}'.format(y[i][j])+\n", " '
z: '+'{:0.5f}'.format(z[i][j]) for j in range(z.shape[1])] for i in range(z.shape[0])]\n", "\n", - "trace1= go.Surface(z=z,\n", - " x=x,\n", - " y=y, \n", - " colorscale=colorscale,\n", - " text=textz,\n", - " hoverinfo='text',\n", - " )" + "trace1= go.Surface(\n", + " x=tuple(x),\n", + " y=tuple(y),\n", + " z=tuple(z),\n", + " colorscale=colorscale,\n", + " text=textz,\n", + " hoverinfo='text',\n", + ")" ] }, { @@ -115,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -126,7 +127,7 @@ "zeroline=False, \n", "showline=False)\n", "\n", - "ztickvals=range(-6,4)\n", + "ztickvals=list(range(-6,4))\n", "layout = go.Layout(title=\"Projections of a surface onto coordinate planes\" , \n", " autosize=False,\n", " width=700,\n", @@ -152,7 +153,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -173,19 +174,19 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 9, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -203,9 +204,9 @@ "texty=[['x: '+'{:0.5f}'.format(x[i][j])+'
z: '+'{:0.5f}'.format(z[i][j]) +\n", " '
y: '+'{:0.5f}'.format(y[i][j]) for j in range(z.shape[1])] for i in range(z.shape[0])] \n", "\n", - "tracex = go.Surface(z=z,\n", - " x=x_offset,\n", - " y=y,\n", + "tracex = go.Surface(z=list(z),\n", + " x=list(x_offset),\n", + " y=list(y),\n", " colorscale=colorscale,\n", " showlegend=False,\n", " showscale=False,\n", @@ -213,9 +214,9 @@ " text=textx,\n", " hoverinfo='text'\n", " )\n", - "tracey = go.Surface(z=z,\n", - " x=x,\n", - " y=y_offset,\n", + "tracey = go.Surface(z=list(z),\n", + " x=list(x),\n", + " y=list(y_offset),\n", " colorscale=colorscale,\n", " showlegend=False,\n", " showscale=False,\n", @@ -223,9 +224,9 @@ " text=texty,\n", " hoverinfo='text'\n", " )\n", - "tracez = go.Surface(z=z_offset,\n", - " x=x,\n", - " y=y,\n", + "tracez = go.Surface(z=list(z_offset),\n", + " x=list(x),\n", + " y=list(y),\n", " colorscale=colorscale,\n", " showlegend=False,\n", " showscale=False,\n", @@ -241,7 +242,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -273,31 +274,17 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to c:\\users\\brand\\appdata\\local\\temp\\pip-req-build-vod_vp7h\n", + " Cloning https://github.com/plotly/publisher.git to /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-req-build-AxIM_I\n", + "Building wheels for collected packages: publisher\n", + " Running setup.py bdist_wheel for publisher ... \u001b[?25ldone\n", + "\u001b[?25h Stored in directory: /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-ephem-wheel-cache-5sJcIZ/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", - " Running setup.py install for publisher: started\n", - " Running setup.py install for publisher: finished with status 'done'\n", "Successfully installed publisher-0.11\n" ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "You are using pip version 10.0.0, however version 10.0.1 is available.\n", - "You should consider upgrading via the 'python -m pip install --upgrade pip' command.\n", - "C:\\Python27\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning:\n", - "\n", - "The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", - "\n", - "C:\\Python27\\lib\\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" - ] } ], "source": [ @@ -316,7 +303,7 @@ " has_thumbnail='true', thumbnail='thumbnail/projection-3d.jpg', \n", " language='python',\n", " display_as='3d_charts', order=19,\n", - " ipynb= '~notebook_demo/79') \n" + " ipynb= '~notebook_demo/79')" ] }, { @@ -345,7 +332,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.14" + "version": "2.7.12" } }, "nbformat": 4,