Plotly Chart Studio

Testing 3D plots using plotly and graph studio.

Here i am using the Iris data set to test embedding graphs into the wordpress site from graph studio

import chart_studio.plotly as py
import plotly.graph_objects as go

iris_df = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')

fig = px.scatter_3d(iris_df, x='petal_length', y='petal_width', z='sepal_width', color='species', symbol='species', size_max=10, title='3D Surface Plot')
fig.update_traces(marker=dict(line=dict(width=2, color='DarkSlateGrey')))
fig.show()

py.plot(fig, filename = '3d-scatter')
# Create a Pandas DataFrame of the iris dataset
iris_df = pd.DataFrame(data=iris.data, columns=iris.feature_names)

# Create the subplots
fig = make_subplots(rows=2, cols=2, subplot_titles=("Petal Length Distribution", "Scatter Plot - Petal Length vs Width", "Scatter Plot - Sepal Length vs Width", "Scatter Plot - Sepal Length vs Petal Length"))

# Add the traces to the subplots
fig1 = go.Histogram(x=iris_df['petal length (cm)'], name='Petal Length')
fig.add_trace(fig1, row=1, col=1)

fig2 = go.Scatter(x=iris_df['petal length (cm)'], y=iris_df['petal width (cm)'], mode='markers', marker=dict(color=iris.target), name='Petal Length vs Width')
fig.add_trace(fig2, row=1, col=2)

fig3 = go.Scatter(x=iris_df['sepal length (cm)'], y=iris_df['sepal width (cm)'], mode='markers', marker=dict(color=iris.target), name='Sepal Length vs Width')
fig.add_trace(fig3, row=2, col=1)

fig4 = go.Scatter(x=iris_df['sepal length (cm)'], y=iris_df['petal length (cm)'], mode='markers', marker=dict(color=iris.target), name='Sepal Length vs Petal Length')
fig.add_trace(fig4, row=2, col=2)

# Update the layout
fig.update_layout(showlegend=False, title='Iris Data Visualization')
py.plot(fig, filename = '3d-scatter - 2x2')
# Show the figure
fig.show()

Leave a Reply

Your email address will not be published. Required fields are marked *