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 @@
Plotly's Python library is free and open source! Get started by downloading the client and reading the primer. +
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!
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
import plotly.plotly as py
@@ -565,12 +565,12 @@ Subcategory Axes
-Out[3]:
+Out[7]:
import plotly.plotly as py
@@ -794,7 +794,7 @@ Reversed Axes
-Out[11]:
+Out[10]:
@@ -812,13 +812,13 @@ Reversed Axes
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
, 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)
See https://plot.ly/python/reference/#layout-xaxis and https://plot.ly/python/reference/#layout-yaxis for more information and chart attribute options!
+See https://plot.ly/python/reference/#layout-xaxis and https://plot.ly/python/reference/#layout-yaxis for more information and chart attribute options!