Hi,
Hope you are well. I wanted to recreate a vector plot like the one below using Plotly:
I have written code (below), that plots the vectors as desired, however, I wanted to assign a colour scale to the colours of the lines. The colours of the lines would be equal to df[βcos2β]. I am unsure of how to proceed and include this. Any help would be much appreciated.
The output of current code:
import pandas as pd
import plotly.graph_objs as go
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import flask
server = flask.Flask(__name__)
app = dash.Dash(__name__, server=server)
file_path = "/Users/mythilisutharson/documents/cam_work/explorer_data/AAML_Oxygen_Data_cos2.csv"
df = pd.read_csv(file_path)
fig = go.Figure()
fig1 = go.Figure()
app.layout = html.Div([
html.Div([
html.Div([dcc.Graph(id='cos2-plot', figure=fig)
], style={},
),
html.Div(
[html.Label(["Remove outliers (if any) in analysis:", dcc.RadioItems(
id='outlier-value-cos2',
options=[{'label': 'Yes', 'value': 'Yes'},
{'label': 'No', 'value': 'No'}],
value='No')
])
], style={'display': 'inline-block',
'width': '49%'}),
])
])
@app.callback(Output('cos2-plot', 'figure'),
[
Input('outlier-value-cos2', 'value'),
])
def update_cos2_plot(outlier):
if outlier == 'Yes':
data = df
counter = 0
lists = [[] for i in range(len(df['line_group'].unique()))]
for i in df['line_group'].unique():
dataf_all = df[df['line_group'] == i]
trace1_all = go.Scatter(x=dataf_all['PC1'], y=dataf_all['PC2'], mode='lines+text',
name=i,
textposition='bottom right', textfont=dict(size=12)
)
lists[counter] = trace1_all
counter = counter + 1
return {'data': lists,
'layout': go.Layout(showlegend=False)}
if __name__ == '__main__':
app.run_server()
Data used for code: