Timeseries streaming in bokeh - python

I want to plot a live time series in bokeh. I want to plot only the new data points at each update. How can I do this ?
There is an example on the bokeh website for animated plots but it involves redrawing the whole picture every time. Also I am looking for a simple example where I can do a live plot of a time series point by point.

As of Bokeh 0.11.1 there is now a streaming interface to column data sources in Bokeh server apps. You can see and easily run an example here:
https://github.com/bokeh/bokeh/tree/master/examples/app/ohlc
That example shows a live updating OHLC chart with MACD indicator (based on synthetic tick data) that only updates the plot with the most recent data points on every update.
Basically, using the streaming interface consists of two parts. First create a new dict with same "shape" as your column data source:
new_data = dict(
time=[t],
open=[open],
high=[high],
low=[low],
close=[close],
average=[average],
color=[color],
)
Then pass this to the .stream method, with an optional rollover argument that specifies how big of a buffer to keep in the browser (earlier data starts to get dropped off):
source.stream(new_data, 300)
Then, just the small amount of data in new_data willbe sent to the plot, not everything.

Related

Managing large number of data in holoviews/hvplot curve and scatter plots

Let's say I have a large DataFrame with lots of rows and I want to do a simple line plot of the data using hvplot/holoviews.
Example:
pd.DataFrame([i for i in range(1000000)]).hvplot()
On my machine this plot is slow to be rendered and very slow to navigate in with pan, zoom and so on. Is there an option to make the plot lighter to handle, kind of what datashade option does for multidimensional plotting?
At the moment, on my real data sampling is not an option, I want to keep all of my original data.
Datashader is not limited to multidimensional data, so just add datashade=True or rasterize=True (which is preferred in most cases, since it lets Bokeh provide colorbars and hover information).

Data cursor on a line plot in python

I am new to python and am looking for a similar feature found in MATLAB. Its called data cursors in signal processing toolbox and I want to use a pre-existing or build a similar one.
The idea is to get a data line which when moved with a mouse and shows the data point of the plotted graph. Linked with the x-axis of the other subplots we can see the data matching of other graphs too.
Is this achievable in python?

Is it possible to combine a stream with no parameters with standard linked streams when declaring a HoloViews DynamicMap?

What I'm trying to do is make an interactive scatter plot where I can control which columns of a DataFrame are on X and Y axes and then select a subset of data using lasso or something similar. Because of the dataset size I have to use datashader.
I tried to declare the DynamicMap as:
dmap = hv.DynamicMap(selector.make_view, kdims=[], streams=[selector, RangeX(), RangeY(), Stream.define('Next')()])
and have a custom callback on the lasso which would select desired rows of data, create the visual representation and update the plot with dmap.event().
So that doesn't seem to work. If I select something, the plot gets updated only when I pan or zoom or change axes selection. VIDEO
If I leave only Stream.define('Next')():
dmap = hv.DynamicMap(selector.make_view, kdims=[], streams=[Stream.define('Next')()])
then lasso updates the plot, but I loose everything else including the ability to zoom. VIDEO
I hope this question makes sense. If needed, I've pushed the notebook here.

Plotting hierarchical clustering dendrograms for large data sets

I have a huge data set of time series data. In order to visualise the clustering in python, I want to plot time series graphs along with the dendrogram as shown below.
I tried to do it by using subgrid2plot() function in python by creating two subplots side by side. I filled first one with series graphs and second one with dendrograms. But once number of time series increased, it became blur.
Can someone suggest a nice way to plot this type of dendrogram? I have around 50,000 time series to cluster and visualise.
Convert data into JSON with json module of python and then use D3.js for graph ploting.
Check the Gallery from here where you can find dendrogram and time series graph

Plotting with Facebook's "fbprophet" Python API, how can I hide "capacity"?

I'm currently playing around with the fbprophet Python API that Facebook just released for time series forecasting.
My forecast dataframe looks like this:
forecast.head()
ds,cap,t,trend,seasonal_lower,seasonal_upper,trend_lower,trend_upper,yhat_lower,yhat_upper,yearly,yearly_lower,yearly_upper,seasonal,yhat
2008-08-01,21064.0,0.0,13534.8985798,295.074941086,3627.77638435,12515.7266808,14582.8551068,12328.7743552,18619.6705558,2330.03631841,611.380084432,3802.86997467,2014.50868144,15549.4072612
2008-09-01,21600.0,0.0101839684625,13431.7394718,1438.43275222,4947.87832578,12450.622301,14428.4657678,13422.5289632,19595.7519179,2545.44444698,1140.23960946,3979.38497822,3089.74759767,16521.4870695
2008-10-01,21966.0,0.0200394218134,13331.908077,1834.90809248,4653.4289911,12382.4033864,14294.8653737,13411.0205974,19818.8904872,2886.28927049,1512.9361508,4269.31963345,3230.24309437,16562.1511714
2008-11-01,14387.0,0.030223390276,13228.7489691,-3351.95070458,-496.310787437,12312.4002068,14162.0170017,8077.85318805,14293.8736792,-2139.69062288,-3514.21626125,-943.144422123,-1895.13014899,11333.6188201
2008-12-01,12377.0,0.0400788436268,13126.5256588,-5241.07039645,-2399.13703352,12246.8937196,14031.1107877,6254.36024438,12626.4645414,-4278.57816444,-5379.58985709,-3176.14935573,-3734.27501375,9392.25064509
This is fine for plotting the simple plot with capacity as a dotted line.
My problem, however, is that if I plot the components
model.plot_components(forecast).show()
see my components_plot
I still get the dotted line of capacity on top of the annual trend line (which is not relevant at all).
My work-around is to delete the column "cap" from the dataframe before plotting.
del forecast['cap']
Isn't there a less destructive way to proceed to plot the trends without the capacity?

Categories

Resources