Usually, when using timevariation function for variation in pollutant concentration with time in openair R package, the hour of the day (on the x axis) spans from 0:00Hr to 23:00Hr.
For example;
timeVariation(filter(MetConc2),
pollutant = "PM2.5", ylab = "PM2.5 (ug/m3)")
But, I need to plot a graph indicating the time frame from 6:00Hr to 5:00Hr, please what code can I use for it. Can anyone help me out.
Related
Hi beginner coder apologise for being basic, im trying to learn to code with pinescript, i just want to draw a box around the NY open, with 9:30-10:30 as left and right sides, and the high and low price within that hour as the top and bottom.
Its for making backtesting easier so eventually want it drawn between the user inputted time period on every NY open, but for now I cant get one to display at all.
I'm not getting any errors, is there a problem with how i'm creating the condition to only draw the box within the two allowed time periods?
Or am I not even close? :)
indicator("justabox", overlay=true)
startdate = input.time(timestamp("15 december 2022 04:00"), title = "Start Date")
enddate = input.time(timestamp("16 december 2022 04:00"), title = "end date")
nysess = not na (time("","0930-1030"))
daytime = time("1D")
onehour = 1000 * 60 * 60
oneminute = 1000 * 60
leftside = daytime + (onehour*9)+(oneminute*30)
rightside = daytime +(onehour*10) +(oneminute*30)
float top = na
float bottom = na
bool indate = na
if (timenow >= startdate and timenow<= enddate)
`indate := true`
else
`indate := false`
if (indate and nysess)
`top := ta.highest(high,12)`
`bottom := ta.lowest(low,12)`
`boxy = box.new(leftside, top, rightside, bottom)`
I was expecting a box to be drawn between 9:30am and 10:30 am with its top and bottom set at the high and low price within that hour.
i tried simplifying the code down to just the user inputted time period as a condition and setting the box at last_bar_index[120] and last_bar_index as its left and right without a session condition and i tried just drawing two lines at high and low price, im following tutorials and dont seem to be doing much different, but i cant find one specific to what im doing.
Thanks for your time.
Check whether the current bar is within the NY open session
nysess = time("0930-1030")
If the current bar is within the NY open session, draw a box
if nysess
top = high
bottom = low
leftside = time("0930")
rightside = time("1030")
boxy = box.new(leftside, top, rightside, bottom)
I have a question. I am trying to plot a live graph while continuously updating a CSV file continuously from a LIDAR sensor. However when I call animation.FuncAnimation(... the graph does not continuously update. If I rerun, I see the graph updated. When I view the CSV file, I see has been updating.
class SecondGraph:
def animate(i):
graph_data = open(NameofCSV,'r').read()
lines = graph_data.split('\n')
xs = []
ys = []
for line in lines:
if len(line) > 0:
x, y = line.split(' ')
xs.append(float(x))
ys.append(float(y))
ax1.clear()
ax1.plot(ys, xs)
ani = animation.FuncAnimation(fig, SecondGraph.animate, interval=10)
When someone has a chance, can someone guide me in the right direction here. I do not think I need to plot my full code, but if you need to see it. Let me know.
Disregard. I think I know the answer. The CSV does not update automatically, which may be the problem. I do not think there is anything wrong with my code that I posted.
It is very critical to learn the start time of each frame of a video.
I need to determine the starting point manually ( for example 848 here) by using below matlab code:
v = VideoReader('video1.avi','CurrentTime',848);
while hasFrame(v)
video_frame = readFrame(v);
counter=counter+1;
if counter==1
imshow(video_frame)
imhist(video_frame(:,:,1))
end
end
What I want is to distinguish some video frame from the others by using histogram. At the end my aim is to reach the exact showing time of the distinguished frames.
After editting:
This is frame histogram outputs:
Histogram size of the some frames are different from the previous one, do you know the reason?
difference=[difference sum(abs(histcounts(video_frame)-histcounts(lastframe)))];
Because of the taking the difference of the I had remove the different histogram sized frames but it causes missing some frames.
i havent found an video example that looks like what you discribe. please condsider always to have an example.
This example code calculates the differences in the histcounts. please notice that waitforbuttonpressis in the loop so you have to click for each frame while testing or remove it when the video is too long. Does this works on your file?
v = VideoReader('sample.avi','CurrentTime',1);
figure1=figure('unit','normalized','Position',[0.2 0.2 0.4 0.6]);
axes1=subplot(3,1,1);
axes2=subplot(3,1,2);
axes3 = subplot(3,1,3);
counter=0;
difference=[];
video_frame=readFrame(v);
while hasFrame(v)
lastframe=video_frame;
video_frame = readFrame(v);
counter=counter+1;
imshow(video_frame,'Parent',axes1);
[a,b]=histcounts(video_frame(:,:,1));
plot(b(1:end-1),a,'Parent',axes2);
difference=[difference sum(abs(histcounts(video_frame,0:255)-histcounts(lastframe,0:255)))];
bar(1:counter,difference,'Parent',axes3);
waitforbuttonpress
end
[~,onedistinguished]=max(difference);
%defining a threshold like every value that is bigger 4000
multidistinguished=find(difference>4000);
disp(['majorly changed at: ' num2str(distinguished)]);
I’m trying to animate a Mayavi pipeline volume:
src = mlab.pipeline.volume(mlab.pipeline.scalar_field(data),vmin=.1*np.max(data),vmax=.2*np.max(data))
that is combined in the pipeline by another dataset represented as a cut plane.
However, I can’t get the volume visualization to update - only the first frame shows up. The animation is stepping through the data correctly (I get different values of the np.max(data[t]) below) but nothing in the visualization changes.
My understanding is that mlab_source_set should re-render correctly, and there’s nothing on the web anywhere that describes this (as far as I can tell).
The animation looks like:
#mlab.show
#mlab.animate(delay=250,ui=True)
def anim(src,data,tax,fig):
"""Animate."""
t = 0
nt = len(tax)
while 1:
vmin = .1*np.max(data[t])
vmax = .2*np.max(data[t])
print 'animation t = ',tax[t],', max = ',np.max(data[t])
src.mlab_source.set(scalar = mlab.pipeline.scalar_field(data[t]), vmin=vmin,vmax=vmax)
t = mod(t+1,nt)
yield
Any thoughts?
This question already has an answer here:
How to create movies on each generation of a for loop in Matlab plot
(1 answer)
Closed 9 years ago.
I have the following code:
figure;
contour(X1,X2,f);
hold on
plot(top(1:size(top,1)), 'rx');
EDIT
figure;
for i = 1: G
contour(X1,X2,f);
hold on
plot(top(1:size(top,1)), 'rx');
end
NB: G is the maximum generation.
This is supposed to plot contours of sphere superimposed with selected individuals. In each iteration of the individuals, the best individuals is selected and these going on until the global optimum is reached. I need to show this in a movie form as shown in this below:
When you runs each stage of the iteration is indicated in the slides attached. This is what i am trying to do. Any idea please?
OK, I am just copying and pasting now, from here.
However I added FrameRate (per second) since you might want to use (or ask) it later.
writerObj = VideoWriter('Your_video.avi');
writerObj .FrameRate = 1; % 1 frames per second animation.
open(writerObj);
fig_h = figure;
for i = 1: G
contour(X1,X2,f);
hold on
plot(top(1:size(top,1)), 'rx');
frame = getframe(fig_h); % or frame = getframe; since getframe gets gcf.
writeVideo(writerObj, frame);
end
close(writerObj);
Now you will have a Your_video.avi file in your working directory.
If VideoWriter is not supported by your matlab, you could use use avifile same as mentioned in this answer (or in mathwork documentaion example here) like this:
aviobj = avifile('Your_video.avi','compression','None', 'fps', 1);
fig_h = figure;
for i = 1:G
contour(X1,X2,f);
hold on
plot(top(1:size(top,1)), 'rx');
frame = getframe(fig_h); % or frame = getframe; since getframe gets gcf.
aviobj = addframe(aviobj, frame);
end
aviobj = close(aviobj);
EDIT
A problem may occur as pointed out by this question also, which is the captured frame is a constant image. If you are running Matlab on windows, this problem may be caused by conjunction of windows in with certain graphics drivers, and may be solved as mentioned in this answer.