Skip to content

Files

Latest commit

5c2107a · Jul 23, 2019

History

History
83 lines (66 loc) · 2.2 KB

plot-data-from-csv.md

File metadata and controls

83 lines (66 loc) · 2.2 KB
jupyter
jupytext kernelspec language_info plotly
notebook_metadata_filter text_representation
all
extension format_name format_version jupytext_version
.md
markdown
1.1
1.2.0
display_name language name
Python 3
python
python3
codemirror_mode file_extension mimetype name nbconvert_exporter pygments_lexer version
name version
ipython
3
.py
text/x-python
python
python
ipython3
3.6.8
description display_as has_thumbnail ipynb language layout name order page_type permalink thumbnail title
How to create charts from csv files with Plotly and Python
databases
false
~notebook_demo/84
python
user-guide
Plot CSV Data
1
example_index
python/plot-data-from-csv/
thumbnail/csv.jpg
Plot Data from CSV | plotly

CSV or comma-delimited-values is a very popular format for storing structured data. In this tutorial, we will see how to plot beautiful graphs using csv data, and Pandas. We will learn how to import csv data from an external source (a url), and plot it using Plotly and pandas.

First we import the data and look at it.

import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_apple_stock.csv')
df.head()

Plot from CSV with Plotly Express

import pandas as pd
import plotly.express as px

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_apple_stock.csv')

fig = px.line(df, x = 'AAPL_x', y = 'AAPL_y', title='Apple Share Prices over time (2014)')
fig.show()

Plot from CSV with graph_objects

import pandas as pd
import plotly.graph_objects as go

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_apple_stock.csv')

fig = go.Figure(go.Scatter(x = df['AAPL_x'], y = df['AAPL_y'],
                  name='Share Prices (in USD)'))

fig.update_layout(title='Apple Share Prices over time (2014)',
                   plot_bgcolor='rgb(230, 230,230)',
                   showlegend=True)

fig.show()

Reference

See https://plot.ly/python/getting-started for more information about Plotly's Python API!