How to interpolate axis labels in matplotlib imshow - python-3.x

I have a scientific 2D matrix that I want to plot. The bin labels are monotonically increasing real numbers which are are frequently on a logarithmic or another non-linear scale. As seen below, replacing the ticks and plotting the bin values directly for each bin is not really very pretty. What are my options?
I would prefer to only make ticks at integer values of each coordinate, even if that tick would not correspond to any particular bin but instead be somewhere in-between the bins.
Another request, if possible, is to then convert the labels to a logarithmic scale, namely, instead of [1,10,100,1000,10000] write 10^1, 10^2, 10^3, 10^4, 10^5.

Related

Understanding Density Plots from Pandas DataFrames

I am trying to understand the distribution of my data for a particular column. It has close to ~1 Million records.
Here is the code that I have written to see the density plot.
df[ "ratio"].plot.kde(bw_method=0.1) # Plot continuous column
https://wellsr.com/python/python-pandas-density-plot-from-a-dataframe/
Here is the plot that I get:
I am not clear what does x-axis and y-axis indicate?
Is x-axis the ratio values from dataframe?
What does Density means in y-axis and how it is calculated?
Do we have any such formula to derive this values in y-axis? I am more interested in deriving the values. Given the column ratio how can we come up with density values. Can someone quickly show the maths?
If you are plotting a KDE, it means you are plotting a Probabilistic Density Function (PDF) of a random variable.
The X-Axis will be the range of values of the parameter you are plotting for. In your case, since you are plotting for Ratio, X-Axis will represent the range of values of your parameter ratio
Y-Axis on the other hand represents kernel density i.e the probability of the parameter your are plotting for.
Read the documentation

Interpolated curves between existing curves do not look correct

I have a chart that has several existing curves on it that I have tried to interpolate new curves in between. I have used linear interpolation in the form of y = ((x - x1)(y2 - y1) / (x2 - x1)) + y1, however the new curves look out of place.
You can see in the picture that every second line (from the bottom) is the interpolated line. While the very second line data points are exactly centered between the first and third data points in the y axis, the third line data points are not centered between the second and fourth y data points, making the graph look skew.
So I am thinking linear interpolation may not be what I am after here. Can someone recommend another method that would create curves between the existing ones, but replicates the same form?
Sudden changes in gradient are hard to interpolate. When you're at the point where you want an interpolated line to suddenly change gradient, there is no information from the points in close proximity that give information as to where the sudden change in gradient should occur.
To replicate the pattern, you actually need to copy the gradient of the line below then smoothly transition to the gradient of the line above. Visually we can see that it should occur half way between the change in gradients for the lines above and below on either side, but detecting the locations of those changes is not trivial.
The points where the sudden change in gradient are occurring are separated by a large change in the x-axis by only a small change in the y-axis. When calculating y-values for x-values in between the the changes in gradient you get the aberrations. I suggest trying to interpolate x-values based on y-values instead. For each curve, for each small arbitrary step in the y-axis, find/calculate the closest x-values from the curve on either side and take the average to plot your interpolation.
An unconventional approach may be a piece-meal style of interpolation. It may be possible to model the 3 regions of different gradients separately.
Start by identifying the 2 lines that would be drawn through the 2 sets of kinks, creating 3 regions of space. The vertical line would stop at the horizontal line near the bottom right corner of the graph.
For each region (and potentially for each value of x in each region) determine the gradient of the lines. When you're doing your interpolation of a new line, for each starting point (x1, y1), look at which region it falls in. Use the gradient of that region as a significant factor when determining the next point. Keep doing this until you reach a region boundary. When the interpolated point crosses into a different region, then use the gradient of that region as a significant factor to interpolate the next point.
It will be quite pointy if you did this strictly, so graph with some smoothing (or incorporate a smoothing factor using weighted averages of the gradients as you transition between regions, but this could be a whole lot of effort without necessarily closer results!)

how to plot mean and standard deviation of multiple measures in gnuplot

I'd like to plot mean and standard deviation of multiple measures in one Gnuplot, if possible.
For example, object A and B has measures of lengths and weights like this (CSV format):
length,weight
100.0,0.1
100.5,0.12
98.8,0.09
100.1,0.11
Is it possible to plot this in a single figure with good visibility, i.e., the length is at the magnitude of 100, while the weight is at 0.1? I don't want the logarithmic way because in my real data, it doesn't make sense to logarithmize them.
Yerrorlines seems an option, but can histogram do this too?
Anyone knows how to do so in Gnuplot?
Thanks!

I want to make a scatter graph of the output of ftrace (from kernel)

I want to make a scatter graph of the output of ftrace (from kernel) on asm_do_IRQ..The problem is there are 8000+ entries and I get the results as a single line plot. Is there any way to do a normalisation of the values so that I can get a scatter plot? The values I want to print are as below:
Interrupt Time
uart-pl011 196.98111
Nomadi 196.983246
prcmu 196.983307
dma40 196.983429
dma40 196.984222
Nomadi 196.98642
dma40 196.988922
prcmu 196.988953
since the number of values are huge, excel takes time on the Y axis and plots the number of interrupts on the X axis. But i want the interrupts by name on the Y axis and time on the X axis.
looks like this is not possible. Scatter graphs can only be used to plot two variables, and since one of the axes i want to plot is a string, this is not possible - i can only get a trend, not the exact plots vs time

Converting angular velocities to orientation Wii Motionplus

I'm working on the Wii Motionplus and I've extracted the raw values using WiimoteLib Library. However, when I normalize it, I get random values that don't tally with what is actually happening.
This is how I'm normalizing:
Calibrate the Motionplus (i.e. Find the raw value that corresponds to zero; I do this by holding it stationary for a point of time)
For every subsequent raw value read, I subtract the zero value from it to get the "relative" raw value.
Then, I scale this value using http://wiibrew.org/wiki/Wiimote/Extension_Controllers (checking for yaw_fast, pitch_fast etc.), where the numerical values are computed using the measure (raw value of 8192 corresponds to 595 deg/s)
I sum up all these values over time (discrete integration) to get the angle of the wiimote wrt initial orientation.
However, when I calculate this and plot it out on a graph, a step change in one of the axes is NOT being reflected in the graph. I tried using a digital compass with it to compare, but while the compass reflects the values correctly, the wii values are completely different (even the pattern is not the same)
Can anyone tell me where I'm going wrong with the normalization?
Thanks!
The numbers that are being sent out are rotations about the x y and z axis respective to itself. In order to relate this to x,y,z coordinates you will need to use a rotation matrix, and since the rotation readings are not a fixed axis but depend on what orientation you are at you need to use a Euler Matrix to relate this to a fixed x,y,z coordinate
In other words you are receiving roll, yaw and pitch velocities and you need to use a Euler Matrix to relate this to cartessian coordinates. Once you know your initial roll, pitch and yaw you can simply add your next reading of roll, pitch and yaw to that initial times the time interval that that reading applies to.
ROLL is Rotation about the y-axis
PITCH is Rotation about the x-axis
YAW is Rotation about the z-axis

Resources