diff --git a/_posts/python/layout/axes/2015-06-30-axes.html b/_posts/python/layout/axes/2015-06-30-axes.html index 89baeb6d6da6..8c9d1eb37b02 100644 --- a/_posts/python/layout/axes/2015-06-30-axes.html +++ b/_posts/python/layout/axes/2015-06-30-axes.html @@ -19,7 +19,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!

@@ -40,7 +40,7 @@

New to Plotly?
-

Toggling Axes Lines, Ticks, Labels, and Autorange¶

+

Toggling Axes Lines, Ticks, Labels, and Autorange

@@ -98,7 +98,7 @@

Toggling Axes Lines,
- +
@@ -111,7 +111,7 @@

Toggling Axes Lines,
-

Tick Placement, Color, and Style¶

+

Tick Placement, Color, and Style

@@ -134,7 +134,7 @@

Tick Placement, Color, and Styledata = [trace1, trace2] layout = go.Layout( xaxis=dict( - autotick=False, + tickmode='linear', ticks='outside', tick0=0, dtick=0.25, @@ -143,7 +143,7 @@

Tick Placement, Color, and Styletickcolor='#000' ), yaxis=dict( - autotick=False, + tickmode='linear', ticks='outside', tick0=0, dtick=0.25, @@ -184,13 +184,13 @@

Tick Placement, Color, and Style
-

Set and Style Axes Title Labels and Ticks¶

+

Set and Style Axes Title Labels and Ticks

-
In [2]:
+
In [4]:
import plotly.plotly as py
@@ -255,12 +255,12 @@ 

Set and Style Axes Title Labe
-
Out[2]:
+
Out[4]:
- +
@@ -273,7 +273,7 @@

Set and Style Axes Title Labe

-

Styling and Coloring Axes and the Zero-Line¶

+

Styling and Coloring Axes and the Zero-Line

@@ -352,7 +352,7 @@

Styling and Coloring Axes a

-

Setting the Range of Axes Manually¶

+

Setting the Range of Axes Manually

@@ -413,13 +413,13 @@

Setting the Range of Axes Manually
-

Subcategory Axes¶

+

Subcategory Axes

-
In [3]:
+
In [7]:
import plotly.plotly as py
@@ -565,12 +565,12 @@ 

Subcategory Axes -
Out[3]:
+
Out[7]:
- +

@@ -583,13 +583,13 @@

Subcategory Axes
-

Logarithmic Axes¶

+

Logarithmic Axes

-
In [9]:
+
In [8]:
import plotly.plotly as py
@@ -628,7 +628,7 @@ 

Logarithmic Axes -
Out[9]:
+
Out[8]:
@@ -646,13 +646,13 @@

Logarithmic Axes
-

Fixed Ratio Axes¶

+

Fixed Ratio Axes

-
In [10]:
+
In [9]:
import plotly.plotly as py
@@ -739,7 +739,7 @@ 

Fixed Ratio Axes -
Out[10]:
+
Out[9]:
@@ -757,13 +757,13 @@

Fixed Ratio Axes
-

Reversed Axes¶

+

Reversed Axes

-
In [11]:
+
In [10]:
import plotly.plotly as py
@@ -794,7 +794,7 @@ 

Reversed Axes -
Out[11]:
+
Out[10]:
@@ -812,13 +812,13 @@

Reversed Axes
-

Reversed Axes with Range ( Min/Max ) Specified¶

+

Reversed Axes with Range ( Min/Max ) Specified

-
In [12]:
+
In [11]:
import plotly.plotly as py
@@ -847,7 +847,7 @@ 

Reversed Axes with Range
-
Out[12]:
+
Out[11]:
@@ -865,7 +865,7 @@

Reversed Axes with Range

-

nonnegative, tozero, and normal Rangemode¶

+

nonnegative, tozero, and normal Rangemode

@@ -926,97 +926,64 @@

nonnegative,
-

Enumerated Ticks with Tickvals and Ticktext¶

+

Enumerated Ticks with Tickvals and Ticktext

-
In [14]:
+
In [15]:
import plotly.plotly as py
-import plotly.tools as tls    
 import plotly.graph_objs as go 
 
-import numpy as np
-from pymatgen.io.vasp import Vasprun
-from pymatgen.electronic_structure.core import Spin
-
-dosrun = Vasprun("Si_bands/DOS/vasprun.xml")
-spd_dos = dosrun.complete_dos.get_spd_dos()
-run = Vasprun("Si_bands/Bandes/vasprun.xml", parse_projected_eigen = True)
-bands = run.get_band_structure("Si_bands/Bandes/KPOINTS", line_mode=True, efermi=dosrun.efermi)
-
-emin = 1e100
-emax = -1e100
-for spin in bands.bands.keys():
-    for band in range(bands.nb_bands):
-        emin = min(emin, min(bands.bands[spin][band]))
-        emax = max(emax, max(bands.bands[spin][band]))
-emin = emin - bands.efermi - 1
-emax = emax - bands.efermi + 1
-
-kptslist = range(len(bands.kpoints))
-bandTraces = list()
-for band in range(bands.nb_bands):
-    bandTraces.append(
-        go.Scatter(
-            x=kptslist,
-            y=[e - bands.efermi for e in bands.bands[Spin.up][band]],
-            mode="lines",
-            line=go.Line(color="#666666"),
-            showlegend=False
-        )
-    )
+import pandas as pd
 
-labels = [r"$L$", r"$\Gamma$", r"$X$", r"$U,K$", r"$\Gamma$"]
-step = len(bands.kpoints) / (len(labels) - 1)
-# vertical lines
-vlines = list()
-for i, label in enumerate(labels):
-    vlines.append(
-        go.Scatter(
-            x=[i * step, i * step],
-            y=[emin, emax],
-            mode="lines",
-            line=go.Line(color="#111111", width=1),
-            showlegend=False
-        )
-    )
+# get and filter apple data
+apple_df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
+apple_df_2016 = apple_df[apple_df.Date < '2017'][apple_df.Date > '2016']
 
-bandxaxis = go.XAxis(
-    title="k-points",
-    range=[0, len(bands.kpoints)],
-    showgrid=True,
-    showline=True,
-    ticks="", 
-    showticklabels=True,
-    mirror=True,
-    linewidth=2,
-    ticktext=labels,
-    tickvals=[i * step for i in range(len(labels))]
-)
-bandyaxis = go.YAxis(
-    title="$E - E_f \quad / \quad \\text{eV}$",
-    range=[emin, emax],
-    showgrid=True,
-    showline=True,
-    zeroline=True,
-    mirror="ticks",
-    ticks="inside",
-    linewidth=2,
-    tickwidth=2,
-    zerolinewidth=2
-)
-bandlayout = go.Layout(
-    title="Bands diagram of Silicon",
-    xaxis=bandxaxis,
-    yaxis=bandyaxis,
+# get clean and filter tesla data
+tesla_df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/tesla-stock-price.csv')
+tesla_df.date = pd.to_datetime(tesla_df.date)
+tesla_df_2016 = tesla_df[tesla_df.date < '2017'][tesla_df.date > '2016']
+
+# set x-axis labels and their corresponding data values
+labels = ['End of Q1', 'End of Q2', 'End of Q3', 'End of Q4']
+tickvals = ['2016-04-01', '2016-07-01', '2016-10-01', apple_df_2016.Date.max()]
+
+data=[
+    go.Scatter(
+        x = apple_df_2016.Date, 
+        y=apple_df_2016['AAPL.High'], 
+        name='Apple', 
+        marker=dict(color='#851e52'),
+    ),
+    go.Scatter(
+        x=tesla_df_2016.date, 
+        y=tesla_df_2016.high, 
+        name='Tesla', 
+        yaxis='y2',
+        marker=dict(color='#d3560e'),
+    ),
+]
+
+layout = go.Layout(
+    title='2016 Quarterly Stock Trends',
+    xaxis=go.layout.XAxis(
+        ticktext=labels,
+        tickvals=tickvals
+    ),
+    yaxis2= dict(
+        overlaying='y',
+        side='right',
+        showgrid=False,
+    )
 )
+fig = go.Figure(data, layout)
 
-bandfig = go.Figure(data=bandTraces + vlines, layout=bandlayout)
-py.iplot(bandfig, filename="Bands_Si", auto_open=False)
+py.iplot(fig)
 
@@ -1029,12 +996,12 @@

Enumerated Ticks with Tickv
-
Out[14]:
+
Out[15]:
- +
@@ -1047,7 +1014,7 @@

Enumerated Ticks with Tickv

-

Reference¶

See https://plot.ly/python/reference/#layout-xaxis and https://plot.ly/python/reference/#layout-yaxis for more information and chart attribute options!

+

Reference

See https://plot.ly/python/reference/#layout-xaxis and https://plot.ly/python/reference/#layout-yaxis for more information and chart attribute options!

diff --git a/_posts/python/layout/axes/axes.ipynb b/_posts/python/layout/axes/axes.ipynb index 475d09edabcc..4913ca36519a 100644 --- a/_posts/python/layout/axes/axes.ipynb +++ b/_posts/python/layout/axes/axes.ipynb @@ -33,7 +33,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -120,7 +120,7 @@ "data = [trace1, trace2]\n", "layout = go.Layout(\n", " xaxis=dict(\n", - " autotick=False,\n", + " tickmode='linear',\n", " ticks='outside',\n", " tick0=0,\n", " dtick=0.25,\n", @@ -129,7 +129,7 @@ " tickcolor='#000'\n", " ),\n", " yaxis=dict(\n", - " autotick=False,\n", + " tickmode='linear',\n", " ticks='outside',\n", " tick0=0,\n", " dtick=0.25,\n", @@ -151,19 +151,19 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 2, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -350,19 +350,19 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 3, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -510,7 +510,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -522,7 +522,7 @@ "" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -563,7 +563,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -575,7 +575,7 @@ "" ] }, - "execution_count": 10, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -664,7 +664,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -676,7 +676,7 @@ "" ] }, - "execution_count": 11, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -709,7 +709,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -721,7 +721,7 @@ "" ] }, - "execution_count": 12, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -803,106 +803,73 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 14, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import plotly.plotly as py\n", - "import plotly.tools as tls \n", "import plotly.graph_objs as go \n", "\n", - "import numpy as np\n", - "from pymatgen.io.vasp import Vasprun\n", - "from pymatgen.electronic_structure.core import Spin\n", - "\n", - "dosrun = Vasprun(\"Si_bands/DOS/vasprun.xml\")\n", - "spd_dos = dosrun.complete_dos.get_spd_dos()\n", - "run = Vasprun(\"Si_bands/Bandes/vasprun.xml\", parse_projected_eigen = True)\n", - "bands = run.get_band_structure(\"Si_bands/Bandes/KPOINTS\", line_mode=True, efermi=dosrun.efermi)\n", - "\n", - "emin = 1e100\n", - "emax = -1e100\n", - "for spin in bands.bands.keys():\n", - " for band in range(bands.nb_bands):\n", - " emin = min(emin, min(bands.bands[spin][band]))\n", - " emax = max(emax, max(bands.bands[spin][band]))\n", - "emin = emin - bands.efermi - 1\n", - "emax = emax - bands.efermi + 1\n", - "\n", - "kptslist = range(len(bands.kpoints))\n", - "bandTraces = list()\n", - "for band in range(bands.nb_bands):\n", - " bandTraces.append(\n", - " go.Scatter(\n", - " x=kptslist,\n", - " y=[e - bands.efermi for e in bands.bands[Spin.up][band]],\n", - " mode=\"lines\",\n", - " line=go.Line(color=\"#666666\"),\n", - " showlegend=False\n", - " )\n", - " )\n", + "import pandas as pd\n", "\n", - "labels = [r\"$L$\", r\"$\\Gamma$\", r\"$X$\", r\"$U,K$\", r\"$\\Gamma$\"]\n", - "step = len(bands.kpoints) / (len(labels) - 1)\n", - "# vertical lines\n", - "vlines = list()\n", - "for i, label in enumerate(labels):\n", - " vlines.append(\n", - " go.Scatter(\n", - " x=[i * step, i * step],\n", - " y=[emin, emax],\n", - " mode=\"lines\",\n", - " line=go.Line(color=\"#111111\", width=1),\n", - " showlegend=False\n", - " )\n", - " )\n", + "# get and filter apple data\n", + "apple_df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')\n", + "apple_df_2016 = apple_df[apple_df.Date < '2017'][apple_df.Date > '2016']\n", "\n", - "bandxaxis = go.XAxis(\n", - " title=\"k-points\",\n", - " range=[0, len(bands.kpoints)],\n", - " showgrid=True,\n", - " showline=True,\n", - " ticks=\"\", \n", - " showticklabels=True,\n", - " mirror=True,\n", - " linewidth=2,\n", - " ticktext=labels,\n", - " tickvals=[i * step for i in range(len(labels))]\n", - ")\n", - "bandyaxis = go.YAxis(\n", - " title=\"$E - E_f \\quad / \\quad \\\\text{eV}$\",\n", - " range=[emin, emax],\n", - " showgrid=True,\n", - " showline=True,\n", - " zeroline=True,\n", - " mirror=\"ticks\",\n", - " ticks=\"inside\",\n", - " linewidth=2,\n", - " tickwidth=2,\n", - " zerolinewidth=2\n", - ")\n", - "bandlayout = go.Layout(\n", - " title=\"Bands diagram of Silicon\",\n", - " xaxis=bandxaxis,\n", - " yaxis=bandyaxis,\n", + "# get clean and filter tesla data\n", + "tesla_df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/tesla-stock-price.csv')\n", + "tesla_df.date = pd.to_datetime(tesla_df.date)\n", + "tesla_df_2016 = tesla_df[tesla_df.date < '2017'][tesla_df.date > '2016']\n", + "\n", + "# set x-axis labels and their corresponding data values\n", + "labels = ['End of Q1', 'End of Q2', 'End of Q3', 'End of Q4']\n", + "tickvals = ['2016-04-01', '2016-07-01', '2016-10-01', apple_df_2016.Date.max()]\n", + "\n", + "data=[\n", + " go.Scatter(\n", + " x = apple_df_2016.Date, \n", + " y=apple_df_2016['AAPL.High'], \n", + " name='Apple', \n", + " marker=dict(color='#851e52'),\n", + " ),\n", + " go.Scatter(\n", + " x=tesla_df_2016.date, \n", + " y=tesla_df_2016.high, \n", + " name='Tesla', \n", + " yaxis='y2',\n", + " marker=dict(color='#d3560e'),\n", + " ),\n", + "]\n", + "\n", + "layout = go.Layout(\n", + " title='2016 Quarterly Stock Trends',\n", + " xaxis=go.layout.XAxis(\n", + " ticktext=labels,\n", + " tickvals=tickvals\n", + " ),\n", + " yaxis2= dict(\n", + " overlaying='y',\n", + " side='right',\n", + " showgrid=False,\n", + " )\n", ")\n", + "fig = go.Figure(data, layout)\n", "\n", - "bandfig = go.Figure(data=bandTraces + vlines, layout=bandlayout)\n", - "py.iplot(bandfig, filename=\"Bands_Si\", auto_open=False)" + "py.iplot(fig, filename='tickvals-and-ticktext')" ] }, { @@ -915,7 +882,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 17, "metadata": { "scrolled": false }, @@ -949,16 +916,18 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-req-build-tp8dF0\n", + " Cloning https://github.com/plotly/publisher.git to /tmp/pip-req-build-WjAJLz\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-QHN64k/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + "\u001b[?25h Stored in directory: /tmp/pip-ephem-wheel-cache-zV6Bvh/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" + "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" ] } ], @@ -1008,7 +977,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.12" + "version": "2.7.15rc1" } }, "nbformat": 4,