I have the following question,
I plotted a graphic using biosspy. Using an integrated function, I could have a list of X-axis coordinates (where there were spikes).
I would like to know if there is a function that given the list o X-axis coordinates can give me the list of the Y-axis coordinates to see the amplitude of the waves.
This is the code, and using the heart_rate_ts it returns the list of the x-axis
from biosppy.signals import bvp
ts, filtered, onsets, heart_rate_ts, heart_rate = bvp.bvp(signal=data1, sampling_rate=50.0, show=True)
Thank you in advance
Related
I have 2 arrays, x and y, respectively representing each point's coordinate on a 2D plane. I also have another 3 arrays of the same length as x and y. These three arrays represent the RGB values of a color. Therefore, each point in x,y correspond to a color indicated by the RGB arrays. In Python, how can I plot a heat map with x,y as its axes and colors from the three RGB arrays? Each array is, say, 1000 in length.
As an example that takes the first 10 points, I have:
x = [10.946028, 16.229064, -36.855, -38.719057, 11.231684, 33.256904999999996, -41.21, 12.294958, 16.113228, -43.429027000000005]
y = [-21.003803, 4.5, 4.5, -22.135853, 4.084630000000001, 17.860079000000002, -18.083685, -3.98297, -19.565272, 0.877016]
R = [0,1,2,3,4,5,6,7,8,9]
G = [2,4,6,8,10,12,14,16,18,20]
B = [0,255,0,255,0,255,0,255,0,255]
I'd like to draw a heat map that, for example, the first point would have the coordinates (10.946028,-21.003803) and has a color of R=0,G=2,B=0. The second point would have the coordinates (16.229064, 4.5) and has a color of R=1,G=4,B=255.
Ok it seems like you want like your own colormap for your heatmap. Actually you can write your own, or just use some of matplotlibs templates. Check out this post for the use of heatmaps with matplotlib. If you want to do it on your own, the easiest way is to recombine the 5 one-dimension vectors to a 3D-RGB image. Afterwards you have to define a mapping function which combines the R-G and B value to a new single value for every pixel. Like:
f(R,G,B) = a*R +b*G + c*B
a,b,c can be whatever you like, actually the formular can be way more complex, but you have to determine in which correlation the values should be. From that you get a 2D-Matrix filled with values of your function f(R,G,B). Now you have to define which value of this new matrix gets what color. This can be a linear mapping by hand (like just writing a list: 0=deep-Blue , 1= ligth-Red ...). Using this look-up table you can now get your own specific heatmap. But as you may see, that path takes some time so i would recommend not doing it and just use one of the various templates of matplotlib. Example:
import matplotlib.pyplot as plt
import numpy as np
a = np.random.random((16, 16))
plt.imshow(a, cmap='hot', interpolation='nearest')
plt.show()
You can use various types of these buy changing the string after cmap="hot" to sth of that list. Hope i could help you, gl hf.
I have a data frame which is indexed by DataTime in pandas.
I have data about a car with the Inside temperature, Lowest inside temperature, Highest temperature and the same three features for the Outside temperature.
Thus I plot all 6 features like so as a time series, and have tried to use plt.fill_between like so :
car_df[['insideTemp','insideTempLow','insideTempHigh','outsideTemp','outsideTempLow','outsideTempHigh']].plot()
plt.fill_between(car_df['insideTemp'], car_df['insideTempLow'],car_df['insideTempHigh'], data=car_df)
plt.fill_between(car_df['outsideTemp'], car_df['outsideTempLow'],car_df['outsideTempHigh'], data=car_df)
plt.show()
I get 6 lines as desired, however nothing seems to get filled (thus not separating the two categories of indoor and outdoor).
Any ideas? Thanks in advance.
You passed wrong arguments to fill_between.
The proper parameters are as follows:
x - x coordinates, in your case index values,
y1 - y coordinates of the first curve,
y2 - y coordinates of the secondt curve.
For readability, usually there is a need to pass also color parameter.
I performed such a test to draw just 2 lines (shortening column names)
and fill the space between them:
car_df[['inside', 'outside']].plot()
plt.fill_between(car_df.index, car_df.inside, car_df.outside,
color=(0.8, 0.9, 0.5));
and got the followig picture:
I want to create a small simulation, and I think I know how, but in order to actually see what happens I need to visualize it.
I started with a 5x5x5 array, which I want to fill up with values.
data = numpy.zeros(shape=(5,5,5))
data[:,:,0]=4
data[:,:,1]=3
data[:,:,2]=2
data[:,:,3]=1
data[:,:,4]=0
This should create a cube which has a gradient in the upward direction (if the third axis is z).
Now, how can I plot this? I dont want a surface plot, or wireframe. Just Points on each coordinate, and maybe colorcoded or transperency by value.
As a test I tried plotting all coordinates using
ax.scatter(numpy.arange(5),numpy.arange(5),numpy.arange(5))
but this will only plot a line consisting of 5 dots.
So... how can I get the 125 dots, that I want to create?
Thx.
You can encode the value in color like this:
x = np.arange(5)
X, Y, Z = np.meshgrid(x,x,x)
v = np.arange(125)
ax.scatter(X,Y,Z, c=v)
See here for the documention.
I have the value of 200 co-ordinates stored in two arrays, plotx_array and ploty_array. This is part of my code to plot the array:
i = 0
while(i<200):
print plotx_array[i], ploty_array[i]
plt.plot(plotx_array[i], ploty_array[i])
plt.axis([200, 400, 100, 320])
i=i+1
plt.show()
This results in a blank graph.
However,If I add "ro" to make the statement:
plt.plot(plotx_array[i], ploty_array[i],"ro")
I get a graph with the co-ordinates plotted with red dots. But I want a continuous line instead of dots, so how do I obtain that?
I have verified that the values fall within the range specified.
IIUC, you're looping and plotting each time a pair, under the assumption that it's a dot plotter. It actually is a vector plotter
Plot lines and/or markers to the Axes. args is a variable length argument, allowing for multiple x, y pairs ...
Try simply replacing the above with
plt.plot(plotx_array, ploty_array)
plt.show()
I am trying to create a cylindrical 3D surface plot using Python, where my independent variables are z and theta, and the dependent variable is radius (i.e., radius is a function of vertical position and azimuth angle).
So far, I have only been able to find ways to create a 3D surface plot that:
has z as a function of r and theta
has r as a function of z, but does not change with theta (so, the end product looks like a revolved contour; for example, the case of r = sin(z) + 1 ).
I would like to have r as a function of z and theta, because my function will produce a shape that, at any given height, will be a complex function of theta.
On top of that, I need the surface plot be able to have (but does not have to have, depending on the properties of the function) an open top or bottom. For example, if r is constant from z = 0 to z = 1 (a perfect cylinder), I would want a surface plot that would only consist of the side of the cylinder, not the top or bottom. The plot should look like a hollow shell.
I already have the function r defined.
Thanks for any help!
Apparently, after some trial and error, the best/easiest thing to do in this case is to just to convert the r, theta, and z data points (defined as 2D arrays, just like for an x,y,z plot) into cartesian coordinates:
# convert to rectangular
x = r*numpy.cos(theta)
y = r*numpy.sin(theta)
z = z
The new x,y,z arrays can be plotted just like any other x,y,z arrays generated from a polynomial where z is a function of x,y. I had originally thought that the data points would get screwed up because of overlapping z values or maybe the adjacent data points would not be connected correctly, but apparently that is not the case.