The problem is that I donโt want to add, I want to set to be equal! (The only set of data be Tup)
Also I donโt want to create a new Figure and Just want to set its Data just equal to Tup!
To be more explicit about my problem:
Imagine that I have a figure with some layout settings and some plotted data, Now I need without remove the figure or without creating a new figure, just set its data to Tup.
Hi @Bijan, I really donโt understand why you want to do this. There is a way to do so, but I personally would not do it and use the update_traces method. Anyway, since it seems to be important for you here is the possible solution:
import pandas as pd
import plotly.graph_objs as go
# data source
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
# Initial figure
fig = go.Figure(
go.Scatter(
x=df['Date'],
y=df['AAPL.High'],
fill='tozeroy',
line=dict(color='rgb(145, 50, 125)'),
name = 'Web'
)
)
# Bijan's tuple
Tup = (
go.Scatter(
x=df['Date'],
y=df['AAPL.Volume']
)
)
# convert fig to dictionary
fig = fig.to_dict()
# update dictionary with Bijan's tuple
fig['data'] = Tup
# create figure from dictionary and show it
fig = go.Figure(fig)
fig.show()
Thanks @AIMPED
Really thanks for all of your always guides and helps.
So Finally also you had to use fig = go.Figure() command again in last line.
Creating a new figure needs to define layouts. In a project I have more than 50 figures and each one have different designed layout and also may have various traces. I want to keep their layouts and simply when I create a new data using go just replace all created data by go instead of current data. update_traces needs to specify the parameter/s name and imagine how hard can it be if you have various figures with various types and various parameters and
it can be imagine how can be simple if we can replace the created data by go into an existing figure with its defined layout and (I think it maybe become faster than recreating figure)
Any way thanks because of your patient and answers