diff --git a/_posts/plotly_js/style/colorway/2018-10-03-colorway.html b/_posts/plotly_js/style/colorway/2018-10-03-colorway.html new file mode 100644 index 000000000000..1a037838b192 --- /dev/null +++ b/_posts/plotly_js/style/colorway/2018-10-03-colorway.html @@ -0,0 +1,33 @@ +--- +name: Set Default Trace Colors with colorway +plot_url: https://codepen.io/plotly/embed/jeqNBq/?height=500&theme-id=15263&default-tab=result +language: plotly_js +suite: colorway +order: 1 +sitemap: false +arrangement: horizontal +--- + +var linspace = require('linspace'); +const parabolaGen = (a, b) => + x => x*x*a + b; + +var as = linspace(1, 3, 7); +var bs = linspace(2, 14, 7); +var x = linspace(-1, 3, 50); +var data = []; + +for (i=0; i< as.length; i++ ){ + data.push({ + type: "scatter", + mode: "lines", + x: x, + y: x.map(parabolaGen(as[i],bs[i])) + }) +} + +var layout = { + colorway : ['#f3cec9', '#e7a4b6', '#cd7eaf', '#a262a9', '#6f4d96', '#3d3b72', '#182844'] +}; + +Plotly.newPlot('myDiv', data, layout); \ No newline at end of file diff --git a/_posts/plotly_js/style/colorway/2018-10-03-colorway_plotlyjs_index.html b/_posts/plotly_js/style/colorway/2018-10-03-colorway_plotlyjs_index.html new file mode 100755 index 000000000000..a6cef2ce5a14 --- /dev/null +++ b/_posts/plotly_js/style/colorway/2018-10-03-colorway_plotlyjs_index.html @@ -0,0 +1,16 @@ +--- +title: Colorway in JavaScript. +name: Colorway +permalink: javascript/colorway/ +description: How to use colorway to set default trace colors in Javascript with Plotly. +layout: base +thumbnail: thumbnail/colorway.jpg +language: plotly_js +page_type: example_index +has_thumbnail: true +display_as: style_opt +order: 3 +--- + +{% assign examples = site.posts | where:"language","plotly_js" | where:"suite","colorway" | sort: "order" %} +{% include auto_examples.html examples=examples %} diff --git a/_posts/python/style/colorway/2015-06-30-colorway.html b/_posts/python/style/colorway/2015-06-30-colorway.html new file mode 100644 index 000000000000..b69e15d86613 --- /dev/null +++ b/_posts/python/style/colorway/2015-06-30-colorway.html @@ -0,0 +1,147 @@ +--- +permalink: python/colorway/ +description: How to set default trace colors with colorway. +name: Colorway +has_thumbnail: true +thumbnail: thumbnail/colorway.jpg +layout: user-guide +language: python +title: Colorway in Python | Plotly +display_as: style_opt +has_thumbnail: true +page_type: example_index +order: 7.9 +ipynb: ~notebook_demo/256 +--- +{% raw %} +
+
+
+
+

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!

+ +
+
+
+
+
+
+
+

Version Check

Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version.

+ +
+
+
+
+
+
In [1]:
+
+
+
import plotly
+plotly.__version__
+
+ +
+
+
+ +
+
+ + +
+ +
Out[1]:
+ + + + +
+
'3.1.1'
+
+ +
+ +
+
+ +
+
+
+
+
+

Set Default Trace Colors with colorway

+
+
+
+
+
+
In [2]:
+
+
+
import plotly.plotly as py
+import plotly.graph_objs as go
+
+import numpy as np
+
+
+def parabola_gen(a, b):
+    return lambda x: a * x ** 2 + b
+
+
+parabolas = [parabola_gen(a, b) for a, b in zip(np.linspace(1, 3, 7), np.linspace(2, 14, 7))]
+x = np.linspace(-1, 3)
+data = [go.Scatter(x=x, y=p(x), mode='lines') for p in parabolas]
+
+colorway = ['#f3cec9', '#e7a4b6', '#cd7eaf', '#a262a9', '#6f4d96', '#3d3b72', '#182844']
+layout = go.Layout(colorway=colorway)
+
+py.iplot(go.Figure(data=data, layout=layout))
+
+ +
+
+
+ +
+
+ + +
+ +
Out[2]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Reference

+
+
+
+
+
+
+
+

See https://plot.ly/python/reference/#layout-colorway for more information about the colorway attribute

+ +
+
+
+ + +{% endraw %} \ No newline at end of file diff --git a/_posts/python/style/colorway/colorway.ipynb b/_posts/python/style/colorway/colorway.ipynb new file mode 100644 index 000000000000..11926d5e4181 --- /dev/null +++ b/_posts/python/style/colorway/colorway.ipynb @@ -0,0 +1,201 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "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", + "
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).\n", + "
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Version Check\n", + "Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3.1.1'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly\n", + "plotly.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Set Default Trace Colors with `colorway`" + ] + }, + { + "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", + "\n", + "import numpy as np\n", + "\n", + "\n", + "def parabola_gen(a, b):\n", + " return lambda x: a * x ** 2 + b\n", + "\n", + "\n", + "parabolas = [parabola_gen(a, b) for a, b in zip(np.linspace(1, 3, 7), np.linspace(2, 14, 7))]\n", + "x = np.linspace(-1, 3)\n", + "data = [go.Scatter(x=x, y=p(x), mode='lines') for p in parabolas]\n", + "\n", + "colorway = ['#f3cec9', '#e7a4b6', '#cd7eaf', '#a262a9', '#6f4d96', '#3d3b72', '#182844']\n", + "layout = go.Layout(colorway=colorway)\n", + "\n", + "py.iplot(go.Figure(data=data, layout=layout))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Reference" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "See [https://plot.ly/python/reference/#layout-colorway](https://plot.ly/python/reference/#layout-colorway) for more information about the colorway attribute." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "execute_result" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting git+https://github.com/plotly/publisher.git\n", + " Cloning https://github.com/plotly/publisher.git to /tmp/pip-req-build-sMJsCC\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-msTCdJ/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.0 is available.\n", + "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n" + ] + } + ], + "source": [ + "from IPython.display import display, HTML\n", + "\n", + "display(HTML(''))\n", + "display(HTML(''))\n", + "\n", + "! pip install git+https://github.com/plotly/publisher.git --upgrade\n", + "import publisher\n", + "publisher.publish(\n", + " 'colorway.ipynb', 'python/colorway/', 'Colorway',\n", + " 'How to set default trace colors with colorway.',\n", + " title = 'Colorway in Python | Plotly',\n", + " has_thumbnail='true', thumbnail='thumbnail/colorway.jpg', \n", + " language='python', \n", + " page_type='example_index',\n", + " display_as='style_opt', \n", + " order=7.9,\n", + " ipynb= '~notebook_demo/256')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15rc1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/_posts/r/style/2018-10-03-colorway.Rmd b/_posts/r/style/2018-10-03-colorway.Rmd new file mode 100644 index 000000000000..7844c3d2f995 --- /dev/null +++ b/_posts/r/style/2018-10-03-colorway.Rmd @@ -0,0 +1,74 @@ +--- +title: Colorway in R | Examples | Plotly +name: Colorway +permalink: r/colorway/ +description: How to set default trace colors using colorway in R with Plotly. +layout: base +language: r +page_type: example_index +has_thumbnail: true +thumbnail: thumbnail/colorway.jpg +display_as: style_opt +order: 5 +output: + html_document: + keep_md: true +--- + +```{r, echo = FALSE, message=FALSE} +knitr::opts_chunk$set(message = FALSE, warning=FALSE) +Sys.setenv("plotly_username"="RPlotBot") +Sys.setenv("plotly_api_key"="q0lz6r5efr") +``` + +### New to Plotly? + +Plotly's R library is free and open source!
+[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).
+You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.
+We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started! + +### Version Check + +Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!
+Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version. + +```{r} +library(plotly) +packageVersion('plotly') +``` + +### Set Default Trace Colors with `colorway` + +```{r, results = 'hide'} +library(plotly) + +x <- seq(-1, 3, length=50) +ones <- rep(1, 50) +a_list <- seq(1, 3, length=7) +b_list <- seq(2, 14, length=7) +df <- data.frame(cbind(x, (outer((x*x), a_list) + outer(ones, b_list)))) + +p <- plot_ly(df, x = ~x, y = ~V2, type = 'scatter', mode = 'lines') %>% + add_trace(y = ~V3) %>% + add_trace(y = ~V4) %>% + add_trace(y = ~V5) %>% + add_trace(y = ~V6) %>% + add_trace(y = ~V7) %>% + add_trace(y = ~V8) %>% + layout(colorway = c('#f3cec9', '#e7a4b6', '#cd7eaf', '#a262a9', '#6f4d96', '#3d3b72', '#182844')) + + +# Create a shareable link to your chart +# Set up API credentials: https://plot.ly/r/getting-started +chart_link = api_create(p, filename="colorway-example") +chart_link +``` + +```{r, echo=FALSE} +chart_link +``` + +#Reference + +See [https://plot.ly/r/reference/#layout-colorway](https://plot.ly/r/reference/#layout-colorway) for more information about the colorway attribute. diff --git a/_posts/r/style/2018-10-03-colorway.md b/_posts/r/style/2018-10-03-colorway.md new file mode 100644 index 000000000000..38283b6ecc9e --- /dev/null +++ b/_posts/r/style/2018-10-03-colorway.md @@ -0,0 +1,74 @@ +--- +title: Colorway in R | Examples | Plotly +name: Colorway +permalink: r/colorway/ +description: How to set default trace colors using colorway in R with Plotly. +layout: base +language: r +page_type: example_index +has_thumbnail: true +thumbnail: thumbnail/colorway.jpg +display_as: style_opt +order: 5 +output: + html_document: + keep_md: true +--- + + + +### New to Plotly? + +Plotly's R library is free and open source!
+[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).
+You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.
+We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started! + +### Version Check + +Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!
+Check out [this post](http://moderndata.plot.ly/upgrading-to-plotly-4-0-and-above/) for more information on breaking changes and new features available in this version. + + +```r +library(plotly) +packageVersion('plotly') +``` + +``` +## [1] '4.8.0' +``` + +### Set Default Trace Colors with `colorway` + + +```r +library(plotly) + +x <- seq(-1, 3, length=50) +ones <- rep(1, 50) +a_list <- seq(1, 3, length=7) +b_list <- seq(2, 14, length=7) +df <- data.frame(cbind(x, (outer((x*x), a_list) + outer(ones, b_list)))) + +p <- plot_ly(df, x = ~x, y = ~V2, type = 'scatter', mode = 'lines') %>% + add_trace(y = ~V3) %>% + add_trace(y = ~V4) %>% + add_trace(y = ~V5) %>% + add_trace(y = ~V6) %>% + add_trace(y = ~V7) %>% + add_trace(y = ~V8) %>% + layout(colorway = c('#f3cec9', '#e7a4b6', '#cd7eaf', '#a262a9', '#6f4d96', '#3d3b72', '#182844')) + + +# Create a shareable link to your chart +# Set up API credentials: https://plot.ly/r/getting-started +chart_link = api_create(p, filename="colorway-example") +chart_link +``` + + + +#Reference + +See [https://plot.ly/r/reference/#layout-colorway](https://plot.ly/r/reference/#layout-colorway) for more information about the colorway attribute. \ No newline at end of file