The essence:
target = 'GOOG'
fig = px.scatter(df, x = target,
y = [c for c in df.columns if c != target],
color_discrete_sequence = px.colors.qualitative.T10,
template = 'plotly_dark', trendline = 'ols',
title = 'Google vs. the world')
The details:
With the latest versions of plotly.express (px) and px.scatter, these things are both easy, straight-forward and flexible at the same time. The snippet below will do exactly as requested in the question.
First, define a target = 'GOOG
from the dataframe columns. Then, using `px.scatter() you can:
- Plot the rest of the columns against the target using
y = [c for c in df.columns if c != target]
- Select a theme through
template='plotly_dark')
or find another using pio.templates
.
- Select a color scheme for the traces through
color_discrete_sequence = px.colors.qualitative.T10
or find another using dir(px.colors.qualitative)
- Define trend estimation method through
trendline = 'ols'
or trendline = 'lowess'
(The following plot is made with a data soure of a wide format. With some very slight amendments, px.scatter()
will handle data of a long format just as easily.)
Plot
Complete code:
# imports
import pandas as pd
import plotly.express as px
import plotly.io as pio
# data
df = px.data.stocks()
df = df.drop(['date'], axis = 1)
# your choices
target = 'GOOG'
colors = px.colors.qualitative.T10
# plotly
fig = px.scatter(df,
x = target,
y = [c for c in df.columns if c != target],
template = 'plotly_dark',
color_discrete_sequence = colors,
trendline = 'ols',
title = 'Google vs. the world')
fig.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…