Can I visualize the outer box of 3D plot? - python

My current plot looks something like this now,
image1
But I'd like to add outer boarders so that I can have a closed box.
Like this,
image2
I am currently using Python3.6,
matplotlib.pyplot
I know that MATLAB gives such options(these images are from MATLAB documentation), so I thought matplotlib may provide the same. But I have failed to find any documentations regarding this issue.
Do I have such options to visualize the outer box, or should I use another package instead?

You may try the method set_frame_on from the class Axes on the current axes.

Related

Matplotlib circle as arrowhead

I am working on a plotting tool for graphs and want to use use circles as arrowheads for FancyArrowPatch when connecting to nodes, like this:
Also I would like to allow three different styles: "o--o", "o--" and "--o".
Is there is a generic way to use Patch objects as arrowheads?
My alternative approach would be to use small circle patches and manually plot them on top of the edges right before the nodes. But this would include calculating the correct coordinates when dealing with curved edges which I would like to avoid. I have already read this answer, but as far as I understand it, the solution won't work with FancyArrowPatch.
Thanks in advance.

Grain Distribution Graph in matplotlib

I am trying to make a graph with matplotlib like the one shown here. The problem I'm running into, is the top part of the graph. I already tried the table option from matplotlib but couldn't get it to work. Another idea is plotting my data over a backgroundimage made with inkscape (Problem is, I don't have any idea how to reference the backgroundimage so that the plot is scientifically correct/precise). So my questions are:
Do you think it is possible with the table option from matplotlib (and i should dig deeper)?
Or is my backgroundimage idea the better choice?
Or is there a complete different approach?
Thanks in advance

Add blur to patch outline in matplotlib?

I am plotting a regular patch in matplotlib, defining an area. However, there is uncertainty around the edges of this area. i would like to add 'blur'.
By brute-forcing it I did it one way - sliced the shape along the x-direction and constructed segments of sub-patches, each with their custom facealpha. I could do this by slicing in 2D and then adjusting facealpha with a more convoluted algorithm.
Any simpler ideas?
I'm not aware of any simple way to do this directly. Matplotlib can do things like drop shadows but that won't give you blur. However, matplotlib's Agg renderer has support for custom filters. You can see examples here.
Specifically, you might be able to do something with the GaussianFilter example. Here I think it's being used to generate the blurred drop shadows but you could figure out how to get it to do what you want in your case. Note that what you are doing in these cases is manually defining a process_image() which works directly on image data.
You may also want to look at this question regarding plotting blurred points.

Can I get imshow() like behaviour in a wx.lib.plot.PlotCanvas?

I'm new to wxpython but have been a matplotlib user for some time now. I am developing a wxpython app in which I would like to have a simple frame with a single panel (actually, a wx.lib.plot.PlotCanvas instance). In the panel I want to show some data, which is in the form of a binary array (called imarr), like this one:
The array will always be of shape (64,N), and N can vary between about 400 and 1200 (I can sort out the panel sizing myself).
To do this in matplotlib I would use something like:
fig=figure(figsize=(12,2))
ax=fig.add_subplot(111)
ax.set_ylim(0,63)
ax.set_xlim(0,imarr.shape[0])
ax.set_aspect('equal')
matplotlib.imshow(imarr)
But I'm completely lost in wxpython. I have been looking into wx.lib.plot, but apart from the nice line and marker plotting capabilities, there doesn't seem to be an equivalent to imshow (or pcolor).
One (ugly) solution I have is to use matplotlib as above to create a png image and then use some wx magic to display the image on a panel (please set me straight if this won't be easy).
I'd much prefer to do it from within wxpython, for portability and general tidiness. Any advice on how to display a binary array on a wx.lib.plot.PlotCanvas (or a more generic wx.Panel) would be very useful!
Why don't you combine wxPython and matplotlib together? wx.lib.plot.PlotCanvas has limited functionality comparing to matplotlib. Have a look at an example in this answer and an example from the matplotlib documentation. Sorry that I didn't answer exactly what you are asking for but I think this is the right way to go.

Best way to create a 2D Contour Map with Python

I am trying to create a 2D Contour Map in Python that looks like this:
In this case, it is a map of chemical concentration for a number of points on the map. But for the sake of simplicity, we could just say it's elevation.
I am given the map, in this case 562 by 404px. I am given a number of X & Y coordinates with the given value at that point. I am not given enough points to smoothly connect the line, and sometimes very few data points to draw from. It's my understanding that Spline plots should be used to smoothly connect the points.
I see that there are a number of libraries out there for Python which assist in creation of the contour maps similar to this.
Matplotlib's Pyplot Contour looks promising.
Numpy also looks to have some potential
But to me, I don't see a clear winner. I'm not really sure where to start, being new to this programming graphical data such as this.
So my question really is, what's the best library to use? Simpler would be preferred. Any insight you could provide that would help get me started the proper way would be fantastic.
Thank you.
In the numpy example that you show, the author is actually using Matplotlib. While there are several plotting libraries, Matplotlib is the most popular for simple 2D plots like this. I'd probably use that unless there is a compelling reason not to.
A general strategy would be to try to find something that looks like what you want in the Matplotlib example gallery and then modify the source code. Another good source of high quality Matplotlib examples that I like is:
http://astroml.github.com/book_figures/
Numpy is actually a N-dimensional array object, not a plotting package.
You don't need every pixel with data. Simply mask your data array. Matplotlib will automatically plot the area that it can and leave other area blank.
I was having this same question. I found that matplotlib has interpolation which can be used to smoothly connect discrete X-Y points.
See the following docs for what helped me through:
Matplotlib's matplotlib.tri.LinearTriInterpolator docs.
Matplotlib's Contour Plot of Irregularly Spaced Data example
How I used the above resources loading x, y, z points in from a CSV to make a topomap end-to-end

Categories