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.
Related
everyone,
I have a generic values distribution. I post the graph.
Is there a way to generate a CDF from these values? Using sns I can create a graph:
My goal is to assign a value to the y-axis and take a value from the x-axis from the CDF. I'm searching online but can't find a method that doesn't require going through curve normalisation.
I'm not sure of the exact data format, but something like numpy.cumsum will take a numpy array that represents a PDF and turn it into an array that represents the CDF.
From there, with your array of p and cdf it is straightforward to find the p value that gives the cdf (which is what I understand you are looking for) with some interpolation with "nearest" as the type of interpolation (see the documentation on scipy.interpolate.interp1d for example).
I am trying to generate a contour graph in terms of three parameters (say x, y, z). These parameters come from a data table of more than 5000 values.I need the graphics to look like the figures shown below.
Contour plots are most easily made using matplotlib's contour.
There's also a corresponding contourf function that provides filled contours. Anyway, what you uploaded looks more like matplotlib's pcolor or pcolormesh, as they draw colored pixels instead of isovalue lines.
Here's a nice comparison of both if you need to choose.
Edit: For (x,y,z) points that are not distributed on a grid (i.e. come from random samples), a working solution seems to be a combination of binned_statistic_2d and then either plt.pcolor or plt.contour.
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)
Is there a way to draw a frequency distribution graph in python or R?
In R, using histograms, which show frequency on y axis vs some categorization on x-axis as in your example.
hist() function at the very least help you plot one vector (a set of values). ?hist for brief documentation, also search this site
how to plot two vectors side by side, similar to your posted example, an example is at http://www.cookbook-r.com/Graphs/Plotting_distributions_(ggplot2)/ , scroll down to Histogram and density plots with multiple groups
Is anybody of you aware of a higher order interpolation method (Catmull-Rom splines, cubic interpolation, etc.) for 2D contouring in Python?
Skimage, Matplotlib, and OpenCV provide the functions measure.find_contours(), contours() and findContours() respectively, but all are based on linear interpolation (also known as marching squares), I'm looking into something with higher accuracy in Python, preferably. Any pointers would be highly appreciated.
https://www.dropbox.com/s/orgr2yqhbbk2xnr/test.PNG
In the image above I'm trying to extract iso-value 25 from the scalar field of f(x,y)=x^3+y^3. I'm looking for 6 points with better accuracy than the 6 red points given by linear interpolation.
For unstructured 2d-data (or triangulated data), you might be interested by the following class:
http://matplotlib.org/api/tri_api.html?highlight=cubictriinterpolator#matplotlib.tri.CubicTriInterpolator
which provides a Clough-Tocher (cubic) interpolator from a user-defined Triangulation and field defined at triangulation nodes. It can also be used through the helper class UniformTriRefiner:
http://matplotlib.org/api/tri_api.html?highlight=refine_field#matplotlib.tri.UniformTriRefiner.refine_field
http://matplotlib.org/mpl_examples/pylab_examples/tricontour_smooth_user.png
Nevertheless the choice of the adapted interpolation depends of course of your data set.