diff --git a/_posts/plotly_js/layout/3d-axes/2015-08-12-3d_axes_fixed_ratio_axes.html b/_posts/plotly_js/layout/3d-axes/2015-08-12-3d_axes_fixed_ratio_axes.html new file mode 100644 index 000000000000..3a74940b2720 --- /dev/null +++ b/_posts/plotly_js/layout/3d-axes/2015-08-12-3d_axes_fixed_ratio_axes.html @@ -0,0 +1,66 @@ +--- +name: Fixed Ratio Axes +plot_url: https://codepen.io/plotly/embed/YRKyeq/?height=500&theme-id=15263&default-tab=result +language: plotly_js +suite: 3d-axes +order: 1.1 +sitemap: false +arrangement: horizontal +--- + +function getrandom(num , mul) + { + var value = [ ] + var i; + for(i=0;i<=num;i++) + { + rand = Math.random() * mul; + value.push(rand); + } + return value; + } + +var i; +traces = []; +names = ['cube', 'data', 'auto', 'manual']; +for (i=1; i<5; i++){ + traces.push({ + x: getrandom(20, 4), + y: getrandom(20, 3), + z: getrandom(20, 5), + opacity:0.5, + mode: "markers", + type: "mesh3d", + scene: "scene" + i, + name: names[i-1] + } + ) +} + +var layout = { + scene:{ + aspectmode:'cube', + domain:{row:0, column:0} + }, + scene2:{ + aspectmode:'data', + domain:{row:1, column:0} + }, + scene3:{ + aspectmode:'auto', + domain:{row:0, column:1} + }, + scene4:{ + aspectmode:'manual', + aspectratio: {x:1, y:1, z:2}, + domain: {row:1, column:1} + }, + grid:{ + pattern: 'independent', + rows:2, + columns:2 + }, + +}; + +Plotly.plot('myDiv', traces, layout); diff --git a/_posts/python/layout/3d-axes/2015-06-30-3d-axes.html b/_posts/python/layout/3d-axes/2015-06-30-3d-axes.html index 02bc3f71922b..589b1ce61e0a 100644 --- a/_posts/python/layout/3d-axes/2015-06-30-3d-axes.html +++ b/_posts/python/layout/3d-axes/2015-06-30-3d-axes.html @@ -15,8 +15,7 @@ ipynb: ~notebook_demo/96 --- {% raw %} -
-
+
@@ -27,8 +26,7 @@

New to Plotly? -
+
@@ -38,7 +36,7 @@

Range of axes + +
+
+
In [2]:
+
+
+
import plotly.plotly as py
+import plotly.graph_objs as go
+import plotly.tools as tls
+import numpy as np
+
+N = 50
+
+fig = tls.make_subplots(
+    rows=2, cols=2,
+    specs=[
+        [{'is_3d': True}, {'is_3d': True}],
+        [{'is_3d': True}, {'is_3d': True}]
+    ],
+    print_grid=False
+)
+for i in [1,2]:
+    for j in [1,2]:
+        fig.append_trace(
+            go.Mesh3d(
+                x=(60*np.random.randn(N)),
+                y=(25*np.random.randn(N)),
+                z=(40*np.random.randn(N)),
+                opacity=0.5,
+              ), 
+            row=i, col=j)
+
+fig['layout'].update(go.Layout(
+                    width=700,
+                    margin=dict(
+                    r=10, l=10,
+                    b=10, t=10)
+                  ))
+
+# fix the ratio in the top left subplot to be a cube
+fig['layout']['scene'].update(go.layout.Scene(aspectmode='cube'))
+
+# manually force the z-axis to appear twice as big as the other two
+fig['layout']['scene2'].update(go.layout.Scene(
+    aspectmode='manual',
+    aspectratio=go.layout.scene.Aspectratio(
+        x=1, y=1, z=2
+    )
+))
+
+# draw axes in proportion to the proportion of their ranges
+fig['layout']['scene3'].update(go.layout.Scene(aspectmode='data'))
+
+# automatically produce something that is well proportioned using 'data' as the default
+fig['layout']['scene4'].update(go.layout.Scene(aspectmode='auto'))
+
+py.iplot(fig, filename='3d-axis-fixed-ratio-axes')
 
@@ -78,10 +166,14 @@

Range of axes - -
-
+
@@ -101,7 +192,7 @@

Set Axes Title
-
In [12]:
+
In [3]:
@@ -146,10 +237,14 @@

Set Axes Title -
Out[12]:
+
+ +
Out[3]:
+ +
- +
@@ -158,8 +253,7 @@

Set Axes Title -
+
@@ -169,7 +263,7 @@

Ticks Formatting
-
In [13]:
+
In [4]:
@@ -215,10 +309,14 @@

Ticks Formatting -
Out[13]:
+
+ +
Out[4]:
+ +
- +
@@ -227,8 +325,7 @@

Ticks Formatting -
+
@@ -238,7 +335,7 @@

Background and Grid Color
-
In [1]:
+
In [5]:
@@ -286,10 +383,14 @@

Background and Grid Color -
Out[1]:
+
+ +
Out[5]:
+ +
- +
@@ -297,4 +398,7 @@

Background and Grid Color" + "" ], "text/plain": [ "" ] }, - "execution_count": 21, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -65,7 +63,89 @@ " b=10, t=10)\n", " )\n", "fig = go.Figure(data=[trace1], layout=layout)\n", - "py.iplot(fig)" + "py.iplot(fig, filename='3d-axis-range')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Fixed Ratio Axes" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.graph_objs as go\n", + "import plotly.tools as tls\n", + "import numpy as np\n", + "\n", + "N = 50\n", + "\n", + "fig = tls.make_subplots(\n", + " rows=2, cols=2,\n", + " specs=[\n", + " [{'is_3d': True}, {'is_3d': True}],\n", + " [{'is_3d': True}, {'is_3d': True}]\n", + " ],\n", + " print_grid=False\n", + ")\n", + "for i in [1,2]:\n", + " for j in [1,2]:\n", + " fig.append_trace(\n", + " go.Mesh3d(\n", + " x=(60*np.random.randn(N)),\n", + " y=(25*np.random.randn(N)),\n", + " z=(40*np.random.randn(N)),\n", + " opacity=0.5,\n", + " ), \n", + " row=i, col=j)\n", + "\n", + "fig['layout'].update(go.Layout(\n", + " width=700,\n", + " margin=dict(\n", + " r=10, l=10,\n", + " b=10, t=10)\n", + " ))\n", + "\n", + "# fix the ratio in the top left subplot to be a cube\n", + "fig['layout'][].update(go.Layout(\n", + " go.layout.Scene(aspectmode='cube')),\n", + " \n", + "\n", + "# manually force the z-axis to appear twice as big as the other two\n", + "fig['layout']['scene2'].update(go.layout.Scene(\n", + " aspectmode='manual',\n", + " aspectratio=go.layout.scene.Aspectratio(\n", + " x=1, y=1, z=2\n", + " )\n", + "))\n", + "\n", + "# draw axes in proportion to the proportion of their ranges\n", + "fig['layout']['scene3'].update(go.layout.Scene(aspectmode='data'))\n", + "\n", + "# automatically produce something that is well proportioned using 'data' as the default\n", + "fig['layout']['scene4'].update(go.layout.Scene(aspectmode='auto'))\n", + "\n", + "py.iplot(fig, filename='3d-axis-fixed-ratio-axes')\n" ] }, { @@ -77,21 +157,19 @@ }, { "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": false - }, + "execution_count": 3, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 12, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -128,7 +206,7 @@ " l=10, t=10)\n", " )\n", "fig = go.Figure(data=[trace1,trace2], layout=layout)\n", - "py.iplot(fig)" + "py.iplot(fig, filename='3d-axis-titles')" ] }, { @@ -140,21 +218,19 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": false - }, + "execution_count": 4, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 13, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -192,35 +268,31 @@ " b=10, t=10)\n", " )\n", "fig = go.Figure(data=[trace1], layout=layout)\n", - "py.iplot(fig)" + "py.iplot(fig, filename='3d-axis-tick-formatting')" ] }, { "cell_type": "markdown", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ "### Background and Grid Color" ] }, { "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false - }, + "execution_count": 5, + "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 1, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -260,15 +332,13 @@ " b=10, t=10)\n", " )\n", "fig = go.Figure(data=[trace1], layout=layout)\n", - "py.iplot(fig)" + "py.iplot(fig, filename='3d-axis-background-and-grid-color')" ] }, { "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": false - }, + "execution_count": 7, + "metadata": {}, "outputs": [ { "data": { @@ -299,23 +369,18 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to /var/folders/ld/6cl3s_l50wd40tdjq2b03jxh0000gp/T/pip-i1yXbl-build\n", + " Cloning https://github.com/plotly/publisher.git to /tmp/pip-req-build-B_WbM3\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-iIz9AA/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + "Successfully built publisher\n", "Installing collected packages: publisher\n", - " Found existing installation: publisher 0.10\n", - " Uninstalling publisher-0.10:\n", - " Successfully uninstalled publisher-0.10\n", - " Running setup.py install for publisher ... \u001b[?25l-\b \b\\\b \bdone\n", - "\u001b[?25hSuccessfully installed publisher-0.10\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/brandendunbar/Desktop/test/venv/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead.\n", - " \"You should import from nbconvert instead.\", ShimWarning)\n", - "/Users/brandendunbar/Desktop/test/venv/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", - " warnings.warn('Did you \"Save\" this notebook before running this command? '\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" ] } ], @@ -341,9 +406,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] } @@ -365,9 +428,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.10" + "version": "2.7.15rc1" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 2 } diff --git a/_posts/r/layout/2017-01-04-3d-axes.Rmd b/_posts/r/layout/2017-01-04-3d-axes.Rmd index 94088d5d08e8..ce8a6127f87c 100644 --- a/_posts/r/layout/2017-01-04-3d-axes.Rmd +++ b/_posts/r/layout/2017-01-04-3d-axes.Rmd @@ -72,6 +72,63 @@ chart_link chart_link ``` +### Fixed Ratio Axes + +```{r, results = 'hide'} +library(plotly) + +# custom grid style +axx <- list( + gridcolor='rgb(255, 255, 255)', + zerolinecolor='rgb(255, 255, 255)', + showbackground=TRUE, + backgroundcolor='rgb(230, 230,230)' +) + +# individual plots +p1 <- plot_ly(z = ~volcano, scene='scene1') %>% + add_surface(showscale=FALSE) + +p2 <- plot_ly(z = ~volcano, scene='scene2') %>% + add_surface(showscale=FALSE) + +p3 <- plot_ly(z = ~volcano, scene='scene3') %>% + add_surface(showscale=FALSE) + +p4 <- plot_ly(z = ~volcano, scene='scene4') %>% + add_surface(showscale=FALSE) + +# subplot and define scene +p <- subplot(p1, p2, p3, p4) %>% + layout(title = "3D Subplots", + scene = list(domain=list(x=c(0,0.5),y=c(0.5,1)), + xaxis=axx, yaxis=axx, zaxis=axx, + + # select the type of aspectmode + aspectmode='cube'), + scene2 = list(domain=list(x=c(0.5,1),y=c(0.5,1)), + xaxis=axx, yaxis=axx, zaxis=axx, + aspectmode='data'), + scene3 = list(domain=list(x=c(0,0.5),y=c(0,0.5)), + xaxis=axx, yaxis=axx, zaxis=axx, + aspectmode='auto'), + scene4 = list(domain=list(x=c(0.5,1),y=c(0,0.5)), + xaxis=axx, yaxis=axx, zaxis=axx, + aspectmode='manual', + + # set your manual fixed aspect ratio + aspectratio = list(x=1, y=1, z=2))) + +# Create a shareable link to your chart +# Set up API credentials: https://plot.ly/r/getting-started +chart_link = api_create(p, filename="axes3d-range") +chart_link +``` + +```{r, echo=FALSE} +chart_link +``` + ### Set Axes Title ```{r, results = 'hide'} diff --git a/_posts/r/layout/2017-01-04-3d-axes.md b/_posts/r/layout/2017-01-04-3d-axes.md index a6ff5164d8d8..0da878407230 100644 --- a/_posts/r/layout/2017-01-04-3d-axes.md +++ b/_posts/r/layout/2017-01-04-3d-axes.md @@ -33,7 +33,7 @@ packageVersion('plotly') ``` ``` -## [1] '4.5.6.9000' +## [1] '4.8.0.9000' ``` ### Range of Axes @@ -70,7 +70,63 @@ chart_link = api_create(p, filename="axes3d-range") chart_link ``` - + + +### Fixed Ratio Axes + + +```r +library(plotly) + +# custom grid style +axx <- list( + gridcolor='rgb(255, 255, 255)', + zerolinecolor='rgb(255, 255, 255)', + showbackground=TRUE, + backgroundcolor='rgb(230, 230,230)' +) + +# individual plots +p1 <- plot_ly(z = ~volcano, scene='scene1') %>% + add_surface(showscale=FALSE) + +p2 <- plot_ly(z = ~volcano, scene='scene2') %>% + add_surface(showscale=FALSE) + +p3 <- plot_ly(z = ~volcano, scene='scene3') %>% + add_surface(showscale=FALSE) + +p4 <- plot_ly(z = ~volcano, scene='scene4') %>% + add_surface(showscale=FALSE) + +# subplot and define scene +p <- subplot(p1, p2, p3, p4) %>% + layout(title = "3D Subplots", + scene = list(domain=list(x=c(0,0.5),y=c(0.5,1)), + xaxis=axx, yaxis=axx, zaxis=axx, + + # select the type of aspectmode + aspectmode='cube'), + scene2 = list(domain=list(x=c(0.5,1),y=c(0.5,1)), + xaxis=axx, yaxis=axx, zaxis=axx, + aspectmode='data'), + scene3 = list(domain=list(x=c(0,0.5),y=c(0,0.5)), + xaxis=axx, yaxis=axx, zaxis=axx, + aspectmode='auto'), + scene4 = list(domain=list(x=c(0.5,1),y=c(0,0.5)), + xaxis=axx, yaxis=axx, zaxis=axx, + aspectmode='manual', + + # set your manual fixed aspect ratio + aspectratio = list(x=1, y=1, z=2))) + +# Create a shareable link to your chart +# Set up API credentials: https://plot.ly/r/getting-started +chart_link = api_create(p, filename="axes3d-range") +chart_link +``` + + ### Set Axes Title @@ -103,7 +159,7 @@ chart_link = api_create(p, filename="axes3d-title") chart_link ``` - + ### Ticks Formatting @@ -141,7 +197,7 @@ chart_link = api_create(p, filename="axes3d-ticks") chart_link ``` - + ### Background and Grid Color @@ -183,7 +239,7 @@ chart_link = api_create(p, filename="axes3d-bg-grid") chart_link ``` - + #Reference