4D heatmap in Python or MATLAB [duplicate] - python

This question already has answers here:
How to create 3D joint density plot MATLAB?
(3 answers)
Closed 5 years ago.
I have a 3D dataset which I visualize with a scatter plot. This is how it looks like:
I would now like to color the different dots depending on the density of the data. Is there any way I can do this in Python or MATLAB? Another option could be to bin the data and color the bins depending on how many data points lie within them. I binned the data by using Python's histogramdd function.
H,edges = np.histogramdd(al,bins=(16,16,16))
The idea is to have it look kind of like this:
using the code provided in this thread: 3D discrete heatmap in matplotlib
If you have any ideas on how I could do this, I would be really happy to hear them!

Thank you all for your ideas. Using the hist3 fundtion does unfortunately not work since I have 3 dimensions and hist3 takes only two variables and calculates the histogram values as the third. My solution for now is to calculate for each data point the number of points which are in a certain radius. Then I use these values to color my plot with scatter3(x,y,z,2,c)
c=zeros(size(x));
for i=1:length(x)
j=1:length(x);
j(i)=[];
s = sort((x(j)-x(i)).^2+(y(j)-y(i)).^2+(d(j)-d(i)).^2);
c(i)=sum(s<2);
end
scatter3(d,x,y,2,c)

Related

How to plot density-contours on a ternary diagram in Python?

I have [x,y,z] data to plot on a ternary diagram, that of which I would like to plot the contours of based on their density in [x,y,z]-space. I have my data stored in a list of ((x1,y1,z1), (x2,y2,z2), ect..), and also in individual data-frame columns.
I see many options (using Marc Harper's function, plotly's 'create_ternary_contour', ect...) for plotting contours based on a 4th dimension (usually output values of a function of x,y,z), but I haven't found a solution to define them based on density. I think what I would like is analogous to the 2D solution available with hist2d and/or contour/contourf using a KDE approach... but on a ternary diagram.
Does anyone know how to do this? I suspect I would have to make some sort of grid in the ternary geometry, and then evaluate the KDE of the [x,y,z] data and define contours based on this somehow? I found a similar question here, but it is unfortunately in R, not Python.

3D plot of 2D pandas data frame - z-axis limits, interactivity

I Posted this question about 3D plots of data frames:
3D plot of 2d Pandas data frame
and the user referred me very very helfully to this:
Plotting Pandas Crosstab Dataframe into 3D bar chart
It use useful and the code worked in principle, but it lookes like a mess (see image below) for several reasons:
I have huge number of values to plot (470 or so, along the y-axis) so perhaps a bar chart is not the best way (I am going for a histogram kind of look, so I assumed very narrow bars would be suitable)
my counts (z axis) do not give almost any information, because the differences I need to see are from 100 to the max value
how can I make the 3D plot that shows up interactive? (being able to rotate etc) - I have seen it done in blogs/videos but sure if it's something on Tools -> Preferences that I can't find
So re: the second issue, simple enough, I tried to just change the limits of the zbar as I would for a 2D Plot, by incorporating:
ax.set_zlim([110,150])
just before the axis labels, but obviously this is the wrong way:
SO do I have to limit the values from the original data set (i.e. filter out <110), or is there a way to do this from the plot?

Can I get a curve like MATLAB in Python? [duplicate]

This question already has answers here:
How to add hovering annotations to a plot
(12 answers)
Closed 3 years ago.
How can I plot a figure in Python like MATLAB with the following features?:
1) I can zoom in and zoom out.
2) I can modify the range for x and y on the figure
3) I can click on the figure to see actual numbers related to each data point
Another question, how can we specify with wath resolution the matplotlib saves the figure?
To the best of my knowledge, MATPLOTLIB does not have that. Anything else?
I would recommend looking at plotly.
Plotly allows you to make graphs that can be
1) zoomed in on
2) change the x and y-axis numbers by dragging on the axes (but cant switch from say, log scale to linear scale as easily -- something like this would require an interaction feature)
3) Plotly allows you to display info on cursor-hover
For an example of a plotly plot in use, see this washington post page.

How do you remove the exponential text in axis values in matplotlib? [duplicate]

This question already has answers here:
Matplotlib: -- how to show all digits on ticks? [duplicate]
(2 answers)
Closed 6 years ago.
On the x-axis, my units are in ns as this is what the physics dictates. However, I don't want the exponential text highlighted to be seen.
Is there anyway this can be removed while keeping the x-axis units the same?
One further question is with regards to sharing the x-axis between the two plots. I want the residual plot on the bottom to be connected to the top while resizing the y-axis.
Previously I set the hspace of the subplots to be 0 but this makes the y-axis values overlap. Are there any solutions to this?
I'd like to point out also that I'm using QuTiP if anyone has expertise in this then that'd be greatly appreciated. I'm sure it should be easy enough to convert the code into a QuTiP style either way.
Any help is appreciated!
Multiply your x data by 1e9, so that you actually plot nanoseconds.

3D mapping of focused ultrasound signal

I have a 3D stage which carries a sensor and measures Ultrasonic signals in 3D space at specified points. What would be the best way of visualizing this data in python?
Your question can be interpreted in two ways:
1) What is a good python tool for drawing such a visualization?
2) What is a good visualization for such data?
I'll tackle both:
1) matplotlib looks sufficient.
2) I think a a 3D scatter plot is a good visualization for such data. This is because you can capture 4 dimensions of data: x,y,z and colour. Also, x,y,z closely resemble space. If it's possible to change the plots' sizes, then you have a 5th dimension.

Categories

Resources