Matplotlib circle as arrowhead - python

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.

Related

How to make a plot that connect its points to its closest neighbors?

I am working on a code to project a given object onto a plane.
The code works fine (at least it seems like it) in achieving that purpose, the only issue I'm having is in plotting my results.
In the image below, for instance, I'm plotting the projection of a parallelepiped (its edges, to be more precise) in a plane of my choice.
I would like to make a plot where each point is connected to its closest neighbor. I'm not very confident that this approach would get the job done, but I think it would be worth the shot.
Different ideas to get there are also welcome!
Any thoughts?
Thanks in advance.
Note: I also tried using a solid line style when plotting as opposed to the pixel marker style, but the result I got was not quite what I expected to say the least:
When telling matplotlib to plot a sequence of points and join them with a line, it creates a straight line between two adjacent points in your input data. To create several lines, it's often easier to split your plot command into several ones. An alternative is to arrange your points such that they form the edges you want, but that would be much more complicated in your case.
As discussed in the comments, separating each edge into its own separate plot command worked for your case.

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.

draw a large graph with many nodes and edges with igraph

I'm trying to visualize a big data set of nodes and edges and I have two files: nodes.txt and edges.txt and I want draw a graph for them. it's got 403,394 nodes and 3,387,388 edges. good to know I generate them randomly.
So I decide using igraph python to draw it by layout and plot but when I try to draw a simple graph with few edges it works but with this huge data set it got an memory error and doesn't work right. I want some help to draw a graph from my edge list with igraph. or maybe there is some better way to do, so suggest it to me.
I use layout with Drl algorithm and use the function plot.

surfaceplot with matplotlib over points xyz

I'm trying to plot a surface over several points it should look like a deformed sphere.
I used the scatter function and plotted the points, but the surface function is not working (the window is empty).
To plot the surface, I think i need a mesh function. I try ed to mash x,y,z but it was not working. How i can generate the code, to put a surface over my points?.
Thanks for helping me.
I have the points xyz stored in a list. They are describing a deformed sphere and i have to plot somthing like this
(source: iop.org)
This question is hard to answer without any sample code of what you're doing, you might want to edit it to include a working example.
I suppose you are using the mplot3d class, have you checked the examples that are provided online here, here, and here? These to me look like what you're trying to produce.

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