mplot3d

Matplotlib 3D plot - 2D format for input data?

我是研究僧i 提交于 2019-12-17 16:25:16
问题 I am plotting a function of two parameters with matplotlib. I copied an example in matplotlib tutorial and transformed with my own input data: vectors X and Y (equally spaces numbers in -3:3) and Z=peaks(X,Y) with peaks a function that I defined befohand. What is wrong? def peaks(x,y): xsq=x**2 ysq=y**2 xsq_one=(x+1)**2 ysq_one=(y+1)**2 m1=3*(1-x)**2 m2=10*(x/5-x**3-y**5) m3=1/3 return m1*numpy.exp(-xsq-ysq_one)-m2*numpy.exp(-xsq-ysq)-m3*numpy.exp(-xsq_one-ysq) from mpl_toolkits.mplot3d

Odd line artefacts appearing in matplotlib mplot3d plot using PolyCollection

一曲冷凌霜 提交于 2019-12-13 04:49:29
问题 I am using the mplot3d example which uses PolyCollection for stacking XY-plots, http://matplotlib.org/examples/mplot3d/polys3d_demo.html However, I am seeing some strange line artefacts in the plots. How can I remove the horizontal lines which disappear out of the visible area? Is there a better way for stacking XY plot along a depth direction? The following script produces this plot, from mpl_toolkits.mplot3d import Axes3D from matplotlib.collections import PolyCollection from matplotlib

Plot normal distribution in 3D

白昼怎懂夜的黑 提交于 2019-12-12 07:38:53
问题 I am trying to plot the comun distribution of two normal distributed variables. The code below plots one normal distributed variable. What would the code be for plotting two normal distributed variables? import matplotlib.pyplot as plt import numpy as np import matplotlib.mlab as mlab import math mu = 0 variance = 1 sigma = math.sqrt(variance) x = np.linspace(-3, 3, 100) plt.plot(x,mlab.normpdf(x, mu, sigma)) plt.show() 回答1: It sounds like what you're looking for is a Multivariate Normal

Plot_trisurf of matplotlib 2.0.2

喜欢而已 提交于 2019-12-10 22:37:01
问题 After updating matplotlib version from 1.3.1 to 2.0.2, when I want to use plot_trisurf to generate a TIN by 3d-points, I got an incomprehensible results. My test code is following: import sys import matplotlib import matplotlib.pyplot as plt from matplotlib.ticker import MaxNLocator from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D import numpy from numpy.random import randn from scipy import array, newaxis chunk = numpy.loadtxt('test.xyz') #test.xyz contains 38010 points,

Defining colors of Matplotlib 3D bar plot

梦想与她 提交于 2019-12-10 22:16:48
问题 I can't figure out the right way to set a cmap (or colors) for a 3d bar plot in matplotlib in my iPython notebook. I can setup my chart correctly (28 x 7 labels) in the X and Y plane, with some random Z values. The graph is hard to interpret, and one reason is that the default colors for the x_data labels [1,2,3,4,5] are all the same. Here is the code: %matplotlib inline from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as npfig = plt.figure(figsize=(18,12))

Plotting a 2d Array with mplot3d

核能气质少年 提交于 2019-12-08 22:58:24
问题 I have a 2D numpy array and I want to plot it in 3D. I heard about mplot3d but I cant get to work properly Here's an example of what I want to do. I have an array with the dimensions (256,1024). It should plot a 3D graph where the x axis is from 0 to 256 the y axis from 0 to 1024 and the z axis of the graph displays the value of of the array at each entry. How do I go about this? 回答1: It sounds like you are trying to create a surface plot (alternatively you could draw a wireframe plot or a

3D parametric curve in Matplotlib does not respect zorder. Workaround?

落花浮王杯 提交于 2019-12-08 02:06:16
问题 I am designing a three-dimensional illustration using Matplotlib. All is working nicely, except that the (red) parametric curve gets the wrong zorder while the (green) parametric surface is drawn completely correctly. Output generated by code below: I know that Matplotlib has limited capabilities for accurately computing the zorder of objects, but since it can do it for the parametric surface, it seems like a bug in Matplotlib. That said, is there any way to force correct z-ordering just to

Scaled colormap of facecolors with mplot3d

若如初见. 提交于 2019-12-07 03:12:00
问题 I have a simple task that should have a simple solution, but I have been trying for days now. I try to be specific. I try to plot a surface using matplotlib's mplot3d and plot_surface. When I plot the surface of a dataset 'z' and try to scale the colormap to a certain maximum value I change the 'vmax' property to this value. That works great. When I try to plot a surface of one dataset (z) and use the facecolors of a second dataset (fc), this also works fine. When I want to scale the colormap

Python - Line colour of 3D parametric curve

☆樱花仙子☆ 提交于 2019-12-06 16:30:06
I have 2 lists tab_x (containe the values of x) and tab_z (containe the values of z) which have the same length and a value of y . I want to plot a 3D curve which is colored by the value of z. I know it's can be plotted as a 2D plot but I want to plot a few of these plot with different values of y to compare so I need it to be 3D. My tab_z also containe negatives values I've found the code to color the curve by time (index) in this question but I don't know how to transforme this code to get it work in my case. Thanks for the help. I add my code to be more specific: fig8 = plt.figure() ax8 =

Animating 3D scatter plot using Python mplotlib via serial data

混江龙づ霸主 提交于 2019-12-06 11:15:37
问题 I am trying to animate a 3D scatter plot using mplotlib in Python. I am able to graph the data and redraw every time, but this results in a frame rate of less than 1 FPS, and I need to scale to upwards of 30 FPS. When I run my code: import serial import numpy import matplotlib.pyplot as plt #import matplotlib library from mpl_toolkits.mplot3d import Axes3D from drawnow import * import matplotlib.animation import time ser = serial.Serial('COM7',9600,timeout=5) ser.flushInput() time.sleep(5)