!#pip install plotly_express
"#pip" no se reconoce como un comando interno o externo, programa o archivo por lotes ejecutable.
import plotly.express as px
print(px.data.iris.__doc__)
iris = px.data.iris()
iris.head()
Each row represents a flower. https://en.wikipedia.org/wiki/Iris_flower_data_set Returns: A `pandas.DataFrame` with 150 rows and the following columns: `['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species', 'species_id']`.
sepal_length | sepal_width | petal_length | petal_width | species | species_id | |
---|---|---|---|---|---|---|
0 | 5.1 | 3.5 | 1.4 | 0.2 | setosa | 1 |
1 | 4.9 | 3.0 | 1.4 | 0.2 | setosa | 1 |
2 | 4.7 | 3.2 | 1.3 | 0.2 | setosa | 1 |
3 | 4.6 | 3.1 | 1.5 | 0.2 | setosa | 1 |
4 | 5.0 | 3.6 | 1.4 | 0.2 | setosa | 1 |
px.scatter(iris,x='sepal_length',y='sepal_width',color='species', title='Sepal height/widht').update(layout=dict(title=dict(x=0.5)))
px.scatter_3d(iris,x='sepal_length',y='sepal_width',z='petal_length',color='species')
px.scatter_matrix(
iris,dimensions=[
'sepal_length',
'sepal_width',
'petal_length',
'petal_width'
],
color='species'
)
import pandas as pd
import numpy as np
import plotly
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
# data = pd.read_csv('./datasets/iris/iris.csv')
data = pd.read_csv('https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/d546eaee765268bf2f487608c537c05e22e4b221/iris.csv')
data.columns = [column.capitalize() for column in data.columns]
# data.columns = data.columns.str.replace('.','_')
data.head()
Sepal_length | Sepal_width | Petal_length | Petal_width | Species | |
---|---|---|---|---|---|
0 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
1 | 4.9 | 3.0 | 1.4 | 0.2 | setosa |
2 | 4.7 | 3.2 | 1.3 | 0.2 | setosa |
3 | 4.6 | 3.1 | 1.5 | 0.2 | setosa |
4 | 5.0 | 3.6 | 1.4 | 0.2 | setosa |
trace = go.Scatter(x=data['Sepal_Length'],
y=data['Sepal_Width'],
mode='markers',
marker=dict(color=np.random.randn(150),
size=10,
colorscale='Viridis',
showscale=False),
)
layout = go.Layout(title='Sepal Length/Sepal width',
xaxis=dict(title='Sepal length'),
yaxis=dict(title='Sepal width'),
)
fig = go.Figure(data=[trace],layout=layout)
iplot(fig)
import plotly.figure_factory as ff
fig = ff.create_scatterplotmatrix(data, index='Species',
height=800, width=800)
iplot(fig, filename='Histograms along Diagonal Subplots')