Switch between monthly and daily bins of stocks data


#1

Hey, I have daily data of some stock.
I want to create a plot and have a button / drop down menu to choose different bins for the xaxis of my daily values. daily / monthly / yearly etc…

is that possible?
I can create the different data on my own (pandas…).

like this


the " Histogram Binning" part.


#2

Hi @koren88i,

What is it that you would like to change about the Histogram Binning example that you linked to above?

-Jon


#3

I don’t understand how to load several data and connect then to the drop down choise…


#4

In the Histogram Binning I do not understand how they specify the y axis…
What is the syntex to take my daily pandas data frame and insert to plots into the same plot…


#5

The Histogram Binning example only use the df[‘date’]. And y is the count of dates in that day/month/quarter/year.


#6

Hi @koren88i,

I see. Yeah the histogram example displays the count on the y-axis. If you want another aggregation that you compute yourself in pandas then you could have the buttons update the trace’s x and y data by using the 'restyle' value of the method parameter. Something like

updatemenus=list([
    dict(
        buttons=list([   
            dict(
                args=[{'x': [daily_df.x], 'y': [daily_df.y]}],
                label='Daily',
                method='restyle'
            ),
            dict(
                args=[{'x': [monthly_df.x], 'y': [monthly_df.y]}],
                label='Monthly',
                method='restyle'
            )             
        ]),
...

Hope that helps!
-Jon


#7

I get
TypeError: unhashable type: ‘DatetimeIndex’ or ndarray etc…

what do I need to put in my args?

More over, is there a list or documentation about what can one put in args??


#8

I think the problem is you wrote a dict inside a list… is that right?


#9

that was the problem.
This worked

args=[‘x’, [monthly_df.index], ‘y’, [monthly_df[df]]]

Another question - I have a figure with 20 subplots. I add each subplot with

fig.append_trace(curr_trace, curr_row, curr_col)

How can I add this button for each figure?


#10

I think the problem is you wrote a dict inside a list… is that right?

Whoops, I accidentally wrote a set rather than a dict. I fixed that above.

Another question - I have a figure with 20 subplots …
How can I add this button for each figure?

You can control which trace the restyle operation applies to by adding a trace numbers list to the end of the args list. e.g. to restyle the third trace added to the figure:

args=[{'x': [daily_df.x], 'y': [daily_df.y]}, [2]]

So you could try adding a series of 20 buttons, where each button references a different trace.

-Jon
-Jon