Bokeh Server Plot - How to make new values appear in the center with a fixed axis range - bokeh

I want to create a plot that shows the live metering data I am getting from an electricity meter.
I already figured out how to have a plot in bokeh, that updates every x seconds with new values, but now I want to have the new values always be at a fixed point in the plot, while the range of the axis does not increase.
I fixed the range by adding x_range=[0, 10] to the figure, however that plot is running out of the screen and I have to manually follow it.
How do I change it so it follows it automatically?
Is that even possible in bokeh or should I be using something different for my project?

Use a default DataRange1d range (i.e. do not set the range to a fixed interval) and then set the follow property on the range. You can also set follow_interval to specify how far back the range should trail the latests data.
p.x_range.follow = "end"
p.x_range.follow_interval = 100
For a complete demonstration see the OHLC ticker example.

Related

How to zoom in the Y-Axis in a line chart using kibana 7.12/7.16

I'm working on an application that get values from different cryptocurrency exchanges and I'm trying to plot that values on Kibana (V 7.12.1) to visually compare the oscillations, everything is working fine (I think), the main application is getting the values from the exchanges and sending to ElasticSearch (V 7.12.1) and I can see the values on Kibana/Discover. I don't have much experience on ElasticSearch/Kibana.
So, in Kibana, I created a new dashboard with a Lens panel, I added the DateTime field to X-axis, ask price and bid price to Y-axis and the exchange name as a break down. The plot looks nice as you can see:
The problem is, at this moment, the values are between 42940 and 43080, a very small difference comparing to the total size of the Y-axis and I can not adjust the Y-axis to get a small window to only see the values of interest.
I don't need different scales to each line, in really it must be the same scale. And values will change over the time, so, the value window will change in size too.
Thanks in advance.
Update:
I did all the same tests on ElasticSearch 7.16.3 and Kibana 7.16.3 and I got exact the same results.
Finally I found it.
There is an Up-Down button to set up the Y-axis, clicking on that button we get the window "Left axis". In that window, the field "Bounds" does this adjust.
Full: to see all the graph;
Data bounds: to automatically adjust the zoom;
Custom: to insert your own limits;

How to set two identical y-scales in the same graph in Labview?

When a graph is very wide I want to show the y-axis values also on the right side of the graph so it becomes easier to read the corresponding values of the lines.
I know how to duplicate the left axis to the right. And when the graph is created I use ActYscl to set the range of scale nr 0 (left) to scale nr 1 (right). This works when the graph is created and also the zoom and pan function work on both y-scales. However, when I use the Autoscale function of the Graph Pallet, only the initial axis is scaled (probably because the graph data are only linked to the original axis).
Is there a way to make the autoscale function work for both y-axis at the same time?
Charts and graphs have an Autoscale Range Change event. Use an event structure to catch this event and update the range of the duplicate scale to match the first one:
I've used a chart for this example as it's simpler, but it should work the same for a graph. Of course you need a way of telling the event loop when to exit; I've used the Value Changed event of the stop button. If your application uses an event-driven structure anyway, you should just be able to add the autoscale event to your existing event loop.

How to set logarithmic scale and axis limits in HistogramLUTItem in pyqtgraph

I'm using pyqtgraph for a live view of a camera acquisition program. Most of the times my images are composed of a lot of background noise and a signal of just a few pixels with higher intensity. For that reason, the part of the HistogramLUTItem that corresponds to the actual signal looks like a thin line and the noise is big next to it. Being able to plot the logarithm of the data would make the data to stand up more.
Is this possible?
I'm currently creating the histogram this way:
imagewidget = pg.GraphicsLayoutWidget()
self.p1 = imagewidget.addPlot()
self.img = pg.ImageItem()
self.p1.addItem(self.img)
self.p1.getViewBox().setAspectLocked(True)
self.hist = pg.HistogramLUTItem()
self.hist.setImageItem(self.img)
self.hist.autoHistogramRange = False
imagewidget.addItem(self.hist)
Doing self.hist.axis.setLogMode(True) didn't work as it affected the x-axis of the histogram instead of the y-axis.
And finally, I would also like to be able to limit the accesible range in the x-axis of the histogram. How can this be done?
Cheers!
Ok, I finally figured out. In case someone wonders, I solved it by adding these two lines:
self.hist.plot.setLogMode(False, True)
self.hist.vb.setLimits(yMin=0, yMax=16000)

add data points to existing plot in R

I try to receive the data from a sensor from time to time and plot it in real time. That means the length of the dataset is not know before hand. And need to adjust the range of the graph dynamically.
I tried the following
plot(1,10, xlim=range(0,10), ylim=range(0,10), type='n')
points(1,data[1])
points(2,data[2])
But once the number of dots is beyond the range of x axis (10 in this case), the data points are out of the range. How to adjust the range accordingly?
Just issue a new plot command with an expanded range. On modern computers the time taken to recreate the plot is small and you generally will not see a delay. Any other approach will essentially do the same thing, clear the current plot and create a new plot.
The ggplot2 and lattice packages have ways of constructing a plot and updating the plot, but when the updated plot is shown it is redrawn from scratch.
There is a zoomplot function in the TeachingDemos package which will allow you to change the range of a plot, but it also will just redraw the plot from scratch (and due to changes in R 3.0.0 it is not currently working, so if you wanted to use it you would need to go back to R 2.15 or before, or wait for it to be fixed).
You can't adjust the range dynamically (sometimes Excel is better). However, you can keep track of what you've plotted, and redo the plot when you've reached the limit. You could also just make a new plot every time you get more data, which would be a way of faking a dynamic update.

Plot single-axis data?

I have a long list of Linux timestamps, representing the second that events occurred over a one-hour period (3600 seconds). Most events are separated by 3-4 seconds but some are separated by one second and some happen at the same second:
1371995100
1371995103
1371995106
1371995106
1371995107
1371995109
1371995111
1371995113
1371995114
1371995118
1371995121
I would like to plot this data as a series of lines representing "event happened", as such (notice that 1371995106 occurs twice):
Actually, since one-second resolution is finer than necessary, but density is important, events that happen at the same time can 'carry over' to the next free second (so it would appear as if the second event that happened at 1371995106 were plotted against the next free second, which is 1371995108):
Can this be plotted using CLI tools in common Linux distros? I have tried plot (gnuplot) but been unable to find examples of creating graphs from one-dimensional data.
You are trying to do a frequency plot. Assuming your data is in a file called data then
set format x "%.0f"
set boxwidth .9
set style fill solid
plot 'data' using ($1):(1) smooth frequency title 'Frequency' with boxes
format stops the label being output with exponents
boxwidth sets the width of the box so there's a gap.
The style is set to filled boxes
smooth frequency sums the y values which are set to 1 by the :(1) the x being the first field in the file ($1).

Resources