I want to draw a time series of stock data.
and then be able to manually draw a line / lines on the graph.
I want to save my line and be able to come back to it later on. delete etcâŚ
is that possible out of the box?
thank you
I want to draw a time series of stock data.
and then be able to manually draw a line / lines on the graph.
I want to save my line and be able to come back to it later on. delete etcâŚ
is that possible out of the box?
thank you
Hi @koren88i,
In the Python library itâs not possible to use the mouse to draw annotations on a plot. This is something that is possible in the online plot.ly chart studio using âShapesâ.
Looking ahead, weâre planning to work out how to best integrate plotly.py with the new open source version of the plot editor, integrated into JupyterLab (https://github.com/plotly/jupyterlab-chart-editor). So the goal is for this kind of chart editing workflow would be available fully offline as well.
If youâre interested, please take a look at the Figure file editor workflow issue and see if you think that would cover your use-case.
Hope that helps!
-Jon
Hey, thank you for responding so quickly.
How do I get to this shapes thing? Iâm kinda lost in the plotly siteâŚ
My ultimate goal is
plot several windows of plots (3x3 grid is ok for my screen), each is a plot of stock close prices for some defined period
for each plot to be able to draw lines
have those lines the next time I load the data (even if i change the period, still see the lines)
I am using tradingview platform today but having to manually do this for every stock is very time consumingâŚ
Is that possible? with the shapes? with plotly?
Hi @koren88i,
Iâm not sure that I have a full picture of what you have in mind, but here are something to try to see if gets you to the workflow youâre after.
make_subplots
approach described here: https://plot.ly/python/subplots/
plotly.plotly.iplot
(not the offline variant)Hope that helps get you started
-Jon
Thank you very much. That sounds a good start for me.
Will report.
After saving a graph. Can I load updated data (e.g a week later) and still see my lines?
I want a âdash boardâ with 6 graphs in 2 columns - each graph being an interactive one. - is that possible?
Hi @koren88i,
So, to update a graph with new data you could pull it back into plotly.py using the plotly.plotly.get_figure
function (Examples). Then you could update the data properties in Python and your lines would remain fixed. If you can copy and paste your data as a table, you could probably also update the data directly in the web interface in the âGridâ pane (The spreadsheet above the plot that holds the raw data).
And yes, you can create a 3x3 grid using the make_subplots
approach I linked to above. You would just configure the subplots to have 3 rows and 3 columns.
Good luck!
-Jon
Ok so I have managed to do almost everything. Great explanation man! Thank you.
Question regarding the update - currently what I am doing is
fig_from_site[âdataâ][1][âxâ] = updated_df.index
fig_from_site[âdataâ][1][âyâ] = updated_df[âadjusted closeâ]
meaning I am updating directly the list I get from the site.
But this means I need to remember which data goes in which place in the list.
the names of those graphs is in the layout part of the figureâŚ
is there a name to get the name of the data so I wont mix up the data of different stocks?
another question
i want to ask questions about each lineâŚ
Hi @koren88i, sounds like youâre making great progress!
Each trace has a name
property that you can use to set and access a custom name for the trace, so you could use your dataframe column name for these. Names are also what show up in the legend by default. You can control whether each trace is present in the legend using the showlegend
property.
You can get a tuple of all of all of the traces using the fig.data
property.
So you should be able to update your figure with something like:
for trace in fig_from_site.data:
trace.y = updated_df[trace.name]
The lines are going to be stored in the fig.layout.shapes
tuple.
Hope that helps!
-Jon
Iâll try that.
Is there a neat way to give a line a name?
Or access lines per graph?
Ok got the naming right.
Iâll iterate through all lines and via the âxrefâ and âyrefâ I will know whoch graph they belong (i will still need to hold a dictionary between graph number and graph name thoughâŚ).
Now for the next problem
the line is two pointsâŚ
I want to know the y value of the line in several other pointsâŚ
I guess there is not an elegant why of doing that? I will have to use the data itself and recompute the line etc�
do not answer yet - working on my own solution and will publish if have problems
OK It is working!
Is it possible to make a âshort cutâ button for drawing lines?
Is it possible to âclickâ on a graph and than have the line shape by default belong to this graph axis?
size of subplots - I want to have each subplot a fixed size, regardless how many subplots i have - is that possible? I get crazy results when trying to play with margins and width etcâŚ
zoom in/out using mouse wheel?
panning as default / pressing âctrlâ for example?
this library is awesome!
Great!
For 1 and 2, are you talking about the chart editor?
from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go
trace1 = go.Scatter(
x=[1, 2, 3],
y=[4, 5, 6],
mode='markers',
textposition='bottom center'
)
nrows = 3
ncols = 2
row_widths = [350] * nrows
column_widths = [500] * ncols
fig = tools.make_subplots(rows=nrows,
cols=ncols,
column_width=column_widths,
row_width=row_widths,
print_grid=False)
for row in range(nrows):
for col in range(ncols):
fig.add_trace(trace1, row=row+1, col=col+1)
fig['layout'].update(width=sum(column_widths), height=sum(row_widths))
fig_widget = go.FigureWidget(fig)
fig_widget
TBH, it doesnât seem like it should be necessary to specify the layout width/height explicitly. But in any case, if you do, it works out
Scroll zoom. You can specify this by adding the config={'scrollZoom': True}
to plotly.offline.plot
. In my testing this works with my touchpad using plotly.offline.plot
(where the figure pops up its own browser window), but it doesnât seem to have any affect with plotly.offline.iplot
(figure inline in notebook). The config
options arenât supported by FigureWidget
yet, but itâs something weâll add at some point (See https://github.com/plotly/plotly.py/issues/1074)
Try pressing shift while dragging in either pan or zoom mode. I think it will temporarily switch between pan and zoom.
Hope some of that was helpful! Glad youâre having fun
-Jon
yes⌠my main work after plotting is drawing horizontal and custom lines on each graph⌠choosing the right axis (and not by nameâŚ) and clicking on shapes-line-custom lines are all actions i want to do less.
yes
this is what i have done - seems to work- is your solution better?
fig = tools.make_subplots(rows=num_rows, cols=num_cols, subplot_titles=([df for df in stocks_dict]), horizontal_spacing=0.2,vertical_spacing=0.2)
curr_row = 1
curr_col = 1
for trace in traces:
curr_trace = traces[trace]
fig.append_trace(curr_trace, curr_row, curr_col)
curr_col+=1
if curr_col % num_cols == 1:
curr_col=1
curr_row+=1
fig[âlayoutâ].update(height=700num_rows, width=700num_cols, title=âPortfolio Stocksâ,
showlegend=False)
I am talking about the chart editor in my browser. not in my jupyter notebook.
likewiseâŚ
after Iâm pulling my data and creating the plots - Iâm looking only at the chart editor⌠and adding lines
then Iâm re downloading the graphs and doing some math about those lines and dataâŚ
then re uploading and loopâŚ
also - loading several graphs makes the chart editor work very slow.
I tried loading only 3 years of information each graph - helpedâŚ
I tried ploting the candles of only open and close (no high low) - helpedâŚ
I tried disabling the slider bar - helped
more ideas?
will buying a non free account help here?
Hi @koren88i,
Unfortunately my knowledge about the chart editor is pretty limited. Iâm not sure if any way to customize/optimize these things. You might try a post in the âChart Studioâ category of the forums.
-Jon
And drawing lines offline? Is that possible?
The offline option is going to be the JupyterLab chart editor. See https://github.com/plotly/jupyterlab-chart-editor. But I donât think it has the capability yet to open existing existing figures (So far itâs focused on opening CSVs and building charts from scratch).
One goal of mine over the next couple of months is to be able to save a figure to a file from plotly.py, open it in the JupyterLab chart editor, edit it (add annotations, etc.), and then save it back to a file. This would make the chart editing workflow available fully offline.
Also, this chart editor is a brand new implementation (compared to the current online chart editor) so it would be great if youâd be interested in trying it out!
-Jon
Iâm confused
Whatâs the difference between the online chart editor and this offline option?