I have followed the post here in order to smooth a 3D scatter plot I have.
My original scatter plot is,
And I would like to get a smooth plot like the following one, that was made using Mathematica,
In the post I mentioned, they use the trisurf function to get a smoother plot. So I though I could use the same to get a similar plot. However, what I get is
As you can see, the triangulation did not work properly. And I don't know how to fix it.
Does anybody know a way to fix this problem? Or is there any other function I could use to smooth my scatter plot?
I think I should mention that my scatter plot is NOT a surface, it is a volume.
Thank you.
Just to clarify this, I post my codes for the original and the trisurf plot eventhough there isn't much to see.
Scatter plot:
S=pd.read_csv("SeparableStatesGrafica.csv",header=None,names=
['P0','P1','P2','P3','P4'])
G=plt.figure().gca(projection='3d')
G.scatter(S['P1'], S['P3'], S['P0'],color='red')
G.set_xlabel("P1")
G.set_ylabel("P3")
G.set_zlabel("P0")
G.view_init(40,40)
plt.show()
Trisurf plot:
S=pd.read_csv("SeparableStatesGrafica.csv",header=None,names=
['P0','P1','P2','P3','P4'])
p0=S['P0'].values
p1=S['P1'].values
p3=S['P3'].values
fig = pylab.figure(figsize=pyplot.figaspect(.96))
ax = Axes3D(fig)
ax.plot_trisurf(p1, p3, p0)
ax.set_xlabel("p1")
ax.set_ylabel("p3")
ax.set_zlabel("p0")
ax.view_init(40,40)
plt.show()
Related
I have a lot of data to create scatter plots for, with each individual plot needing to be saved. Each plot shares the same axis. Currently I have this which works:
for i in dct:
plt.figure()
plt.scatter(time_values, dct[i])
plt.title(i)
plt.xlabel("Time")
plt.ylabel("values")
plt.xticks(x_labels,rotation=90)
plt.savefig(os.path.join('some_file_path','image{}.png'.format(str(self.image_counter))))
plt.close('all')
However, it is very slow at actually creating the graphs. The answer here How could I save multiple plots in a folder using Python? does what I want, however only for a normal plot. Is there anyway I can implement something like this with a scatter plot? I have tried converting by data into a 2D array, however my x_axis values are a string and so it does not accept the array
Actually, you can plot scatter plots with plt.plot(x, y, 'o') and re-use that code by example.
Given below is the code for plotting points using pyplot.
x1=300+p[k]*math.cos(val[thetaval])
y1=300+p[k]*math.sin(val[thetaval])
plt.plot(x1,y1,'k.')
The plotting is working fine, the problem is, if I want to plot it as a point I am specifying the dot in 'k.' inside the plot function. The output is something like:
The width of the black line/curve that I am plotting is much more that needed. How to reduce it?
It seems that you are not plotting a line but a series of small points. Maybe if you try setting the markersize argument of the plot function could work.
Looking into the documentation of plot() you can find "linewidth"
So use:
plt.plot(x1,y1,'k.', linewidth=0.1)
I want to make a figure which has similar axis to the example below. I know I could use loglog plot. But in this example, the step-size (x-axis) decreases when you go farther to the right.
How could I do this in python (using matplotlib)
Possibly the invert_xaxis call is what you are looking for. As follows:
fig = plt.figure()
ax = fig.add_axes()
ax.invert_xaxis()
Link: http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes
I need to return both a histogram and a scatterplot in one function using matplotlib, but when I try to create the histogram after creating the scatterplot, it appears that the scatterplot gets overridden. Just wondering if anyone has any advice on this issue? Is there a way to return two plots at once if they share an x-axis?
For instance, there is paragraph included in this link http://matplotlib.org/users/pyplot_tutorial.html about how to have 2 subplots. But I'm not sure how to do that with plt.hist() and plt.plot().
Since the histogram fills the bars it is probably better to do it first then the scatter plot.
I am currently plotting two completely different datasets into one 3D surface plot. When I am plotting each one independently, everything works fine. However, as soon as I plot them in one, the visualization is strange. I do the plotting the following way:
fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X,Y,Z, color=color, antialiased=True)
(get new X,Y, Z values)
ax.plot_surface(X,Y,Z, color=color, antialiased=True)
ax.view_init(30, 360)
The output is the following:
As you can see, the blue data is correct, but the green one is somehow in the backside and not correctly visualized. If I plot the green one alone, it works perfectly.
Changing the order of plotting (or playing around with zorder) does not change anything.
Hope someone can help!
Matplotlib is just a 2d plotting library. 3d plots are achieved by projecting the 3d surface onto the image plane.
If you have multiple 3d surfaces, it will turn each into a 2d shape, and then calculate a single height for each shape, and show then in that order.
As far as I'm aware, the zorder option doesn't work, and all it would is change the order of the surfaces anyway.
If you're really unlucky, the grey boxes that make up the axis grids can get plotted above your surface too. That's even more annoying.
Of you must use matplotlib, then i guess you could split up your surface into lots of smaller ones, but you're going to encounter a pretty big performance bit doing this, and you'll to override the values in the legend too.