3D grid with python - python

I have a set of data, 5 columns: (x,y,z,Temperature, Pressure), is not a regular mesh, is data from well logging. I would like to make a 3d grid in order to make some vertical cut. How can I do it?

Your question isn't very clear about what you want. If it is a graph packages like seaborn and matplotlib can make 3D graphs that can display heatmap information.

Related

A 2D bar chart in a 3D chart using Plotly

I am trying to plot 2D bars in a Plotly 3D figure. I understand that Plotly's 3D figures do not yet support bar charts out of the box, but I have come across some examples from other people on the Plotly forums which have shown how this might be achieved.
Please see the post Adding a shape to a 3D plot. This is close to what I am trying to achieve, but I am not trying to plot a histogram.
It appears plotting traces as a mesh3d, adding in the missing points and triangulating is the way to go for Plotly's 3D chart, according to other examples I have seen. Below is an example of what I am looking for that I created using Matplotlib.
As you can see, x axis is the date, y axis is the trace name and z axis is the value. I would like to see if I can achieve something similar using Plotly's 3D charts, which are so much better of course because of the client side interactivity.
Is there a working example for what I'm trying to achieve? I am simply looking to plot simple (date, value) per trace as 2D bars in the 3D figure.
There isn't any current way to have a bar chart in 3D with Plotly (at least that I am aware of).
Documentation: Plotly Python Open Source Graphing Library 3D Charts
As shown in the documentation, there aren’t any options for a bar chart. There are, however, alternatives like a bubble chart.

Plotting points within a triangle

I'm using Python, and I have some data which can be projected on to points within an equilateral triangle whose side lengths sum to 1.
I'm not sure if there is an easy way to visualise a plot like this from Matplotlib or similar libraries, or if I'm just going to have to use a drawing package from scratch to make it happen. Any pointers gratefully recieved. Thanks!
If all you want to do is plot a few dots on a graph, you can infact use Matfplotlib's scatter plots for this:
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html
Using plt.xlim(*min*, *max*) and plt.ylim(*min*, *max*), you can set the limits of the graph manually to fit your values (might not be neccessary though).
You can draw lines on the graph for the triangle shape (if you need that): How to draw a line with matplotlib?
If you don't need a scale, you can even remove that to have a blank canvas: Matplotlib plots: removing axis, legends and white spaces

Draw Basemap above xarray plot

I have a xarray dataset clip_ds and have visualised the data array using plot. Now, I want to add a country boundary using Basemap's drawcountries(). Apparently, there is something wrong with the extent I am using in basemap (I guess), but both the country border and the data plot won't show up together. I have tried interchanging the position of clip_ds.pr[0].plot() before and after I create basemap, and it gives me two different results as shown below:
Xarray PLOT BEFORE BASEMAP (Note that the colorbar from xarray plot is still there)
Xarray PLOT AFTER BASEMAP (Notice difference from 3, height of the plot shrinks here and the tick labels disappears, probably overlapped by basemap.)
Xarray plot only
Loading seperate shapefile using map.readshapefile also gives same kind of problem. I know there might be a way around this using cartopy, but I like the Basemap functionalities and would like to know if there is any solution to this.
map=Basemap(projection='merc',
resolution='l',
llcrnrlon=clip_ds.lon[0],
llcrnrlat=clip_ds.lat[0],
urcrnrlon=clip_ds.lon[-1],
urcrnrlat=clip_ds.lat[-1])
map.drawcountries()
clip_ds.pr[0].plot()
plt.show()

How to add box plots on top of scatter plot

I want to plot boxplots on top of the scattered points like this.
I know I have to bin the data into intervals first but I couldn't find the function that does all of this. Sample x and y data are saved here as .npy.
I would look into using matplotlib. Boxes can be drawn as such:
https://matplotlib.org/gallery/pyplots/boxplot_demo_pyplot.html?highlight=boxplot
and scatter plots can also be drawn as such: https://matplotlib.org/gallery/lines_bars_and_markers/scatter_demo2.html?highlight=scatter
There is a search functionality on their site, along with plenty of documentation on how to utilize their library.
As for your specific question, you can specify zorder when drawing many of the things in matplotlib, and you could use that to define your boxplots to be on top. I believe if no zorder is defined that it draws items in the order they are encountered in your program (so you could draw scatter plots and then box plots and they should appear correctly as in your diagram above!

How to make data points in a 3D python scatter plot look like "discs" instead of "spheres"

In a standard 3D python plot, each data point is, by default, represented as a sphere in 3D. For the data I'm plotting, the z-axis is very sensitive, while the x and y axes are very general, so is there a way to make each point on the scatter plot spread out over the x and y direction as it normally would with, for example, s=500, but not spread at all along the z-axis? Ideally this would look like a set of stacked discs, rather than overlapping spheres.
Any ideas? I'm relatively new to python and I don't know if there's a way to make custom data points like this with a scatter plot.
I actually was able to do this using the matplotlib.patches library, creating a patch for every data point, and then making it whatever shape I wanted with the help of mpl_toolkits.mplot3d.art3d.
You might look for something called "jittering". Take a look at
Matplotlib: avoiding overlapping datapoints in a "scatter/dot/beeswarm" plot
It works by adding random noise to your data.
Another way might be to reduce the variance of the data on your z-axis (e.g. applying a log-function) or adjusting the scale. You could do that with ax.set_zscale("log"). It is documented here http://matplotlib.org/mpl_toolkits/mplot3d/api.html#mpl_toolkits.mplot3d.axes3d.Axes3D.set_zscale

Categories