Plotting a histogram using a csv file - csv

I have a csv file with the following format.
Label 1, 20
Label 2, 10
Label 3, 30
.
.
.
LabelN, 5
How do I plot the second column using the labels given in the csv file as labels on the x-axis?
(Something like this, where 1891-1900 is a label)
EDIT:
Found these questions which are quite similar to mine,
Plotting word frequency histogram using gnuplot
Gnuplot xticlabels with several lines
After trying the commands given in answer 1.
set xtics border in scale 1,0.5 nomirror rotate by -90 offset character 0, 0, 0
plot "data.txt" using 2:xticlabels(1) with histogram
I'm getting a not so clean histogram because the number of labels is quite large. I've tried the formatting given in answer 2. Can anyone suggest a way to get a cleaner histogram?

You have several options:
Plot only the important labels (extremes, mean etc. for example)
Skip every 5th label or so if labels form a series
Split your graph if you must plot every single label.
Seems like case 2) applies here, and thus skipping some of the labels before plotting will make the plot look better.
You can pre-process the file to skip every 5th label (say) using something like the following script:
line_number = 0
for line in open("d1.txt", "r"):
line_split = line.split(",")
if(line_number % 5 == 0):
print line,
else:
print ",",line_split[1],
line_number += 1
You can now plot with appropriate font size
set xtics border in scale 1,0.5 nomirror rotate by -90 offset character 0, 0, 0
set xtics font ",9"
plot "d2.txt" using 2:xticlabels(1) with histogram title "legend_here"

Related

Interpretation of yolov5 output

I am making a face mask detection project and I trained my model using ultralytics/yolov5.I saved the trained model as an onnx file, you can find the model file here model.onnx. Now I want you use this model.onnx with opencv to detect real time face mask. The input image size during training was 320*320. You can visualize this model using netron.
I have written this code to capture the image using webcam and pass it to model.onnx to predict my bounding boxes. The code is as follows:
def predict(img):
session = onnxruntime.InferenceSession(model_path)
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name
img = img.reshape((1,3,320,320))
data = json.dumps({'data':img.tolist()})
data = np.array(json.loads(data)['data']).astype('float32')
result = session.run([output_name],{input_name:data})
result = np.array(result)
print(result.shape)
The output of result.shape is (1, 1, 3, 40, 40, 85)
Can anyone help me in interpreting this shape and how can i use this result array to predict my class, bounding box and confidence.
I've never worked with a pure yolov5 model, but here's the output format for yolov5s. It looks like it should be similar.
ouput tensor structure (yolov5s):
output_tensor[a, b, c, d]
a -> image index (If you're input is a batch of images, this tells you which image's output you're looking at. If your input is just one image, leave this as 0.)
b -> index of image in batch
c -> information about bounding box
0, 1 -> x and y coordinate of bounding box center
2, 3 -> width and height of bounding box
4 -> bounding box confidence
5 - 85 -> single class confidences
d -> index of proposed bounding boxes

Cut ultrasound signal between specific values using Octave

I have an ultrasound wave (graph axes: Volt vs microsecond) and need to cut the signal/wave between two specific value to further analyze this clipping. My idea is to cut the signal between 0.2 V (y-axis). The wave is sine shaped as shown in the figure with the desired cutoff points in red
In my current code, I'm cutting the signal between 1900 to 4000 ms (x-axis) (Aa = A(1900:4000);) and then I want to make the aforementioned clipping and proceed with the code.
Does anyone know how I could do this y-axis clipping?
Thanks!! :)
clear
clf
pkg load signal
for k=1:2
w=1
filename=strcat("PCB 2.1 (",sprintf("%01d",k),").mat")
load(filename)
Lthisrun=length(A);
Pico(k,1:Lthisrun)=A;
Aa = A(1900:4000);
Ah= abs(hilbert(Aa));
step=100;
hold on
i=1;
Ac=0;
for index=1:step:3601
Ac(i+1)=Ac(i)+Ah(i);
i=i+1
r(k)=trapz(Ac)
end
end
ok, you want to just look at values 'above the noise' in your data. Or, in this case, 'clip out' everything below 0.2V. the easiest way to do this is with logical indexing. You can take an array and create a sub array eliminating everything that doesn't meet a certain logical condition. See this example:
f = #(x) sin(x)./x;
x = [-100:.1:100];
y = f(x);
plot(x,y);
figure;
x_trim = x(y>0.2);
y_trim = y(y>0.2);
plot(x_trim, y_trim);
From your question it looks like you want to do the clipping after applying the horizontal windowing from 1900-4000. (you say that that is in milliseconds, but your image shows the pulse being much sooner than 1900 ms). In any case, something like
Ab = Aa(Aa > 0.2);
will create another array Ab that will only contain the portions of Aa with values above 0.2. You may need to do something similar (see the example) for the horizontal axis if your x-data is not just the element index.

How can I plot a file.dat in gnuplot maching points with lines?

My problem is when I plot the points of my file (x, y, sen(y)*cos(x)) (50x50 points from -6 to 6) and use with lines like that:
splot 'C:\Users\pablo\Documents\Programs\Fortran 90\CUAT 2\Graph\plot.dat' u 1:2:3 w l
... gnuplot match with lines all points from the x axis (1,1 to 50,1) and then link the 50,1 with 1,2. That's result on a continuos line imposible to fill with pm3d. I tried to use dgrid3d 500,500, it's takes a bit to load but it ignores lost of points. I want to use "with lines" in a way that match points making squares (1,1 to 1,2 to 2,2 to 2,1 to 1,1...). I don't know why it works with:
splot sen(y)*cos(x) w l
... but not with plot.dat
How can I match points with lines making squares?

How to gnuplot a csv file containing temperature and humidity, label only every nth entry

I have a .csv file, containing the log of a temperature / humidity sensor (ELV TFD 128). The data is logged every minute, like this (translation: "Number;Date;Temperature in degree Celsius, Humidity in %"):
Nummer;Datum;Temperatur in °C;Luftfeuchtigkeit in %
0;17-Nov-2013 9:54:14;25,90;52
1;17-Nov-2013 9:55:13;25,80;53
2;17-Nov-2013 9:56:12;25,50;53
3;17-Nov-2013 9:57:11;25,20;53
4;17-Nov-2013 9:58:10;25,00;53
5;17-Nov-2013 9:59:10;24,90;54
6;17-Nov-2013 10:00:09;24,80;54
7;17-Nov-2013 10:01:08;24,70;54
8;17-Nov-2013 10:02:07;24,70;54
9;17-Nov-2013 10:03:06;24,50;54
10;17-Nov-2013 10:04:05;24,50;54
(...)
I'd like to gnuplot the data, but only label every n th element (lets say, every 60th) on the x axis with the second csv element - the date and time. As the label is quite long (17-Nov-2013 10:04:05), I'd like to angle the label away from the x axis by roughly 45 degrees so that the second "touches" (or points to) the x axis at the correct position.
As always, I'd appreciate any help or pointers in the right direction.
In order to set the xrange and tics in gnuplot for a time axis, you can use something like the following
set xrange ["17-Nov-2013 12:00:02":"30-Nov-2013 12:00:00"]
set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0
Important is to set the time format correctly, i.e.
set timefmt "%d-%b-%Y %H:$M:%s"
See, i.e. help set timefmt, help set xtics for more detailed explanations. I didn't try, but with set xtics you should be able to suit it exactly to your needs, by specifying a spacing.

Matplotlib/Pyplot: How to zoom subplots together?

I have plots of 3-axis accelerometer time-series data (t,x,y,z) in separate subplots I'd like to zoom together. That is, when I use the "Zoom to Rectangle" tool on one plot, when I release the mouse all 3 plots zoom together.
Previously, I simply plotted all 3 axes on a single plot using different colors. But this is useful only with small amounts of data: I have over 2 million data points, so the last axis plotted obscures the other two. Hence the need for separate subplots.
I know I can capture matplotlib/pyplot mouse events (http://matplotlib.sourceforge.net/users/event_handling.html), and I know I can catch other events (http://matplotlib.sourceforge.net/api/backend_bases_api.html#matplotlib.backend_bases.ResizeEvent), but I don't know how to tell what zoom has been requested on any one subplot, and how to replicate it on the other two subplots.
I suspect I have the all the pieces, and need only that one last precious clue...
-BobC
The easiest way to do this is by using the sharex and/or sharey keywords when creating the axes:
from matplotlib import pyplot as plt
ax1 = plt.subplot(2,1,1)
ax1.plot(...)
ax2 = plt.subplot(2,1,2, sharex=ax1)
ax2.plot(...)
You can also do this with plt.subplots, if that's your style.
fig, ax = plt.subplots(3, 1, sharex=True, sharey=True)
Interactively this works on separate axes
for ax in fig.axes:
ax.set_xlim(0, 50)
fig.draw()