plotly memorandum

plotly sample

import

import plotly
import plotly.graph_objs as go

import pandas as pd
import numpy as np

Data read

df = pd.read_csv('https://raw.githubusercontent.com/jbrownlee/Datasets/master/daily-total-female-births.csv')
df['Births2'] = df['Births'] + np.random.normal(0, df['Births'].std(), [len(df)]).astype(int)
df['Births3'] = df['Births'] + np.random.normal(0, df['Births'].std() * 2, [len(df)]).astype(int)

df = df.loc[:50, :]

Liune Chart

tr1 = go.Scatter(x=df["Date"], y=df["Births"], mode="lines+markers")
layout = go.Layout(
    title="Births",
    xaxis=dict(title="date"),
    yaxis=dict(title="births")
)
plotly.offline.iplot(dict(data=[tr1], layout=layout))

image.png

Save and show fig

plotly.offline.iplot(dict(data=[tr1], layout=layout), filename='result', image="png")

Value display

tr1 = go.Scatter(x=df["Date"], y=df["Births"], mode="lines+markers+text", text=df["Births"], textposition="top center")
layout = go.Layout(
    title="Births",
    xaxis=dict(title="date"),
    yaxis=dict(title="births")
)
plotly.offline.iplot(dict(data=[tr1], layout=layout))

image.png

Multiple data display

tr1 = go.Scatter(x=df["Date"], y=df["Births"], mode="lines+markers", name="Births")
tr2 = go.Scatter(x=df["Date"], y=df["Births2"], mode="lines+markers", name="Births2")
tr3 = go.Scatter(x=df["Date"], y=df["Births3"], mode="lines+markers", name="Births3")
layout = go.Layout(
    title="Births",
    xaxis=dict(title="date"),
    yaxis=dict(title="births")
)
plotly.offline.iplot(dict(data=[tr1, tr2, tr3], layout=layout))

image.png

scatter

tr1 = go.Scatter(x=df["Date"], y=df["Births"], mode="markers")
layout = go.Layout(
    title="Births",
    xaxis=dict(title="date"),
    yaxis=dict(title="births")
)
plotly.offline.iplot(dict(data=[tr1], layout=layout))

image.png

Histogram

tr1 = go.Histogram(x=df["Births"], xbins=dict(start=0, end=101, size=5))
layout = go.Layout(
    title="Births",
    xaxis=dict(title="birth"),
    yaxis=dict(title="count"),
    bargap=0.2
)
plotly.offline.iplot(dict(data=[tr1], layout=layout))

image.png

Multiple data display

tr1 = go.Histogram(x=df["Births"], xbins=dict(start=0, end=101, size=5))
tr2 = go.Histogram(x=df["Births2"], xbins=dict(start=0, end=101, size=5))
layout = go.Layout(
    title="Births",
    xaxis=dict(title="birth"),
    yaxis=dict(title="count"),
    bargap=0.2,
    bargroupgap=0.2
)
plotly.offline.iplot(dict(data=[tr1, tr2], layout=layout))

image.png

Recommended Posts

plotly memorandum
Matplotlib memorandum
linux memorandum
Python memorandum
Django memorandum
Command memorandum
Python Memorandum 2
Slackbot memorandum (1)
multiprocessing memorandum
Memorandum MetaTrader 5
[Linux/LPIC] Memorandum
ShellScript memorandum
pip memorandum
Python memorandum
pydoc memorandum
python memorandum
Pandas memorandum
python memorandum
DjangoGirls memorandum
Command memorandum
Python memorandum
pandas memorandum
python memorandum
Python memorandum
[Visualization] I tried using Bokeh / plotly! 【memorandum】
Python basics memorandum
RAID type memorandum
Python pathlib memorandum
Knapsack problem memorandum
Memorandum of sed
Python memorandum (algorithm)
Linux memorandum [links]
nc command memorandum
Deep Learning Memorandum
numpy memorandum 1 / np.pad
Revit API memorandum
Memorandum conda command
Pandas operation memorandum
setuptools command memorandum
Python memorandum [links]
tslearn trial memorandum
Django's basic memorandum
Memorandum about validation