Set Y-axis in FLOT depending on value - flot

How can I set the min and max value of the Y-axis, when it is depending on the highest value, for example 32 (degrees celsius) than I would like a max value of a few degrees higher, with scale linesof 5 degreez

See the documentation on axes costumization for this:
First, try setting the tickSize: 5 option
If flot's automatic tick generation still does not what you want, try also setting the max and min options. For max you could calculate the next multiple of 5 greater than your data maximum (something like max = 5 * (Math.floor(32/5) + 1)).
If all this fails, use the ticks option and give it an array with the specific values you want to have on your axis (something like [0, 5, 10, 15, 20, 25, 30, 35]).

Related

How to normalize samples of an ongoing cumulative sum?

For simplicity let's assume we have a function sin(x) and calculated 1000 samples between -1 and 1 with it. We can plot those samples. Now in the next step we want to plot the integral of sin(x) which would be - cos(x) + C. Now i can calculate the integral with my existing samples like this:
y[n] = x[n] + y[n-1]
Because it's a cumulative sum we will need to normalize it to get samples between -1 and 1 on the y axis.
y = 2 * ( x - min(x) / max(x) - min(x) ) - 1
To normalize we need a maximum and a minimum.
Now we want to calculate the next 1000 samples for sin(x) and calculate the integral again. Because it's a cumulative sum we will have a new maximum which means we will need to normalize all of our 2000 samples.
Now my question basically is:
How can i normalize samples in this context without knowing the maximum and minimum?
How can i prevent, to normalize all previous samples again, if i have a new set of samples with a new maximum/minimum?
I've found a solution :)
I also want to mention: This is about periodic functions like Sine, so basically the maximum and minimum should be always the same, right?
In a special case this isn't true:
If you samples don't contain a full period of the function (with global maximum and minimum of the function). This can happen when you choose a very low frequency.
What can you do:
Simply calculate the samples for a function like sin(x) with a
frequency of 1. It will contain the global maximum and minimum of the function (it's important that y varies between -1 and 1, not 0 and 1!).
Then you calculate the integral with the cumulative sum.
get maximum and minimum of the samples
you can scale it up or down: maximum/frequency, minimum/frequency
can be used now to normalize samples which were calculated with any other frequency.
It only need to be calculated once at the beginning.

Is it possible to get MIN and MAX VALUE with ONE priority_queue?

If I have a queue which is {1, 3, 10, 22}
and I need max and min value (22, 1)
so I made maxHeap and minHeap with priority_queue, and I got two priority_queue.
but I need just max and min. I think that I just make one maxheap and get max in root and get min in (where). If possible.
So is it possible to get MAX & MIN with just one maxheap or minheap?
Or I must make two priority queues?

random numbers from geometric distribution such that their sum equals SUM

I want to draw k random numbers i_1,...,i_k with min <= i <= max from an exponentially shaped distribution of values with m,std being median and standard of the population's values. The sum(i1,..,ik) should equal a given parameter SUM.
Example:
Given:
k = 9 SUM = 175 min = 8 max = 40 m = 14
Desired:
[9, 10, 11, 12, 14, 17, 23, 30, 39]
I don't know if this is actually possible without depending on luck to draw a combination satisfying the SUM rule. I'd appreciate any kind of help or comment. Thank you.
EDIT: In a former version I wrote about exponentional distributions where an exact solution is impossible, rather I meant an exponentially shaped distribution with discrete values like a geometric distribution for instance.
EDIT2: Corrected the number k in the example.

Choose a random value between 0.00 and 20.00

In Excel, it is possible to select a random value from a set of 5 options in the following manner:
Values
e.g. 15, 30, 50, 75, or 100
Formula
=CHOOSE(RANDBETWEEN(1,5),15,30,50,75,100)
If I wanted to select a value from a much denser range how would I do it?
e.g. 0.00, 0.01, 0.02, 0.03 ,0.04 ,0.05 ... 19.95, 19.96, 19.97, 19.98, 20.00
What would be the correct formulae?
Consider the following formula:
=0.01*RANDBETWEEN(0,2000)
This will produce random multiples of .01
Scale the output of the random function by multiplying/dividing it by a constant.
For instance, if your Random function outputs floating decimal values between 0 and 1, and you need outputs between 0 and 100, multiply the output of the random function by 100.
If you need the final result to be an integer, you can then round the value to the nearest integer.
It sounds like you want
=ROUND(RAND()*20,2)
The 20 is the maximum value of your zero-to-maximum range, and the 2 is how many decimal places it'll round the final output to.

how to transform the values to show in graph according to pixels in iphone/ipad?

I need to show values in bar graph. I am drawing the bars using CALayer. And there are only three bars in my case. And the bar height changes for different values. I am drawing each bar as a rectangle of variable height( height according to pixcel value).
I am able to draw the maximum height as 300 pix. But, the values in y-axis (height) are
1, 4, 10
1000, 230, 12000
in this way.
How can I scale these values to pixel values? I have to show the values in y-axis ?
Thank you,
This might be a little bit of an old post but why couldnt you take your max possible value:
Say it can never exceed 12,000 / max size you can plot.
Then when you create your bars, the size is that % of it.
Example
1, 2, 5, 100, 1000, 10000, 20000
Assuming your max height was 300px...
Take the largest number 20,000 and divide by the largest pixel size possible 300px
You get .015 percent.
This means you multiply each value by .015 and plot it and it should show you a true to scale graph of the values.

Resources