short: I want to connect dots that are close to each other in a 3D scatter plot with lines to get some "3D wired look" 3D model.
Background: I got from a microscope an image stack from a fish. I want to show specific cells in that fish. The Software gives me X, Y, Z values of these cells and I'm plotting them in a scatter 3D plot. To get an context I collected a lot of values (XYZ) from the skin too and want to plot them "around" the whole thing to get the look of an fish. If I would be able to connect these dots with lines Id get some kind of "wired" fish which would be great. It would be even greater if id be able to fill the planes in the wire (that would be a 3D fish).
#data of the cells
X = np.array(df["X"])
Y = np.array(df["Y"])
Z = np.array(df["Z"])
#data of the fishskin
XF = np.array(df["XF"])
YF = np.array(df["YF"])
ZF = np.array(df["ZF"])
ax.scatter(XF, YF, ZF, s=40, c='b', marker='o')
ax.scatter(XV, YV, ZV, s=40, c='r', marker='o')
plt.show()
that's what I did so far, very basic but hey, I'm rookie.
The only language I'm a little into is Python but I also got MatLab and toyed around with Blender a little. If you think my problem would be a lot easier to solve in one of these programs (maybe model the fish in blender end import him to Python or whatever) tell me! I was searching around the whole day but maybe I'm using the wrong keywords or something because I wasn't successful.
If I understand your question correctly, you would like to create an unstructured triangular grid. If this is the case, then I suggest you check out this tutorial on the Matplotlib website.
I am trying to build a website. One part of the website needs that a graph is show based on user input. It will be built using Django.
I have checked out a few options, mpld3 proving to be at least better than the others. The graph is kind of animated(?) as the scatter plots appear after a pause. This is a feature which would be great if I could include it.
So while using mpld3, I faced two problems:
1. When I run the python script, I have an image as a background for the graph. This does not appear when I use mpld3 to render it to a webpage.
2. Only the final plots appear. Is there a way that I can show the points coming up on the graph one by one with pauses as it is supposed to?
Here is part of the code with the necessary details. In case there's any further detail, I'll be glad to provide it.
fig, ax = plt.subplots()
im = plt.imread('map_main.png')
implot = plt.imshow(im)
plt.axis([0, width, 0, height])
plt.ion()
for i in locations:
x, y = locations[i]
plt.scatter(x, y, c='b')
plt.pause(0.05)
locations contain a bunch of coordinates where the scatter points are supposed to show up.
Any help on what I should study next to achieve this would be great. Thanks.
I have a binned data of an x-axis n-length vector and 3 y-axis n-length vector for 3 different histograms on the same x-axis.
Now I want this kind of stacked bar plot or any thing similar as below.
The nearest I have found is Qtiplot (which is not python). It can generate exactly this kind of histogram plots. But it computes the histogram by itself and requires the actual data samples which are not present in my case (I only have the histogram itself).
Please note that I don't know python very well. So I don't have a clue from where I shall start, neither I am really in a mood to learn programming in python. I need this only to make a nice vector-graphics plot for my research thesis.
I have tagged python as I think python is the most obvious language. In case someone knows any better solution other than in python (but not Matlab, I cannot install that huge pile), I will thankfully add the proper tag.
Thanks in advance for any help.
use matplotlib package in python
import matplotlib.pyplot as plt
apple_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
banana_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
mango_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
fig=plt.figure()
ax1=fig.add_subplot(311)
ax2=fig.add_subplot(312)
ax3=fig.add_subplot(313)
ax1.hist(apple_weight)
ax2.hist(banana_weight)
ax3.hist(mango_weight)
plt.show()
import matplotlib.pyplot as plt
apple_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
banana_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
mango_weight=[3,3,3,10,10,1,1,1,4,4,4,4,7,7,7]
fig=plt.figure()
ax1=fig.add_subplot(111)
ax2=ax1.twinx()
#only two y axes so the third list just add to either
ax1.hist(apple_weight)
ax2.hist(banana_weight)
ax1.hist(mango_weight)
plt.show()
The bug is documented here:
Matplotlib errorbar not centered on marker
and here:
https://github.com/matplotlib/matplotlib/issues/3400
Basically, the markers are plotted off by 1 pixel all the time.. You can even see this on Matplotlib's own tutorial page if you look closely at the second plot: http://matplotlib.org/1.2.1/examples/pylab_examples/errorbar_demo.html
This is very frustrating as I cannot produce publication-quality plots from matplotlib, and I'm very surprised this has not been fixed.
In any case, I have too much time and code invested into matplotlib to switch to a different package. So my question is how would you go about making a workaround? I suppose one solution is to plot the markers 1 pixel to the left/right from the errorbars. I don't know how to do this. I figured out how to get the display coordinates of my plot points, but how can I make an interactive plot that preserves the 1-pixel offset? I can plot them with 1-pixel offsets, but then you can't zoom or manipulate the plot.
It seems like the Matplotlib team have fixed the issue when calling savefig() using .svg or .pdf, but for .png I've found that you can circumvent this issue by using an odd number for the error line thickness. Using the first example on the Matplotlib tutorial, if we use
plt.errorbar(x, y, yerr=0.4, marker='X', markersize=15)
then the bars are offset like this:
However if we use a line width of 3
plt.errorbar(x, y, yerr=0.4, marker='X', markersize=15, elinewidth=3)
then the bars are centred like this:
This isn't a perfect solution, but it does the job if you don't mind having slightly thicker lines.
I have to translate an image plotting script from matlab to matplotlib/pylab, and I'm trying to achieve the same effect as the matlab image below:
As you can see, the z order of the plots seem to be higher than the z order of the grid, so the markers are not hidden by the axes. However, I can't figure out a way to do the same with my matplotlib image:
I'm wondering if it is possible to get the same display without having to increase the limits of the y axis.
To get the marker to show beyond the axes you can turn the clipping off. This can be done using the keyword argument in the plot command clip_on=False.
For example:
import matplotlib.pyplot as plt
plt.plot(range(5), range(5), 'ro', markersize=20, clip_on=False, zorder=100)
plt.show()
This is a complete example of how to use the zorder kwarg: http://matplotlib.sourceforge.net/examples/pylab_examples/zorder_demo.html
Note that a higher z-order equates to a graph-element being more in the foreground.
For your second question, have a look at the figsize kwarg to instances of the Figure class: http://matplotlib.sourceforge.net/api/figure_api.html?highlight=figsize#matplotlib.figure.Figure
If you run into issues, please post some of your code and we'll be able to give more-detailed recommendations. Best of luck.
If you're plotting the lines one after the other, just change the order of the plotting calls and that would fix the z order.