mplot3d

Drawing a righthand coordinate system in mplot3d

无人久伴 提交于 2019-12-22 22:02:34
问题 I want to create plots from Python of 3D coordinate transformations. For example, I want to create the following image (generated statically by TikZ): A bit of searching led me to the following program: import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib.patches import FancyArrowPatch from mpl_toolkits.mplot3d import proj3d class Arrow3D(FancyArrowPatch): def __init__(self, xs, ys, zs, *args, **kwargs): FancyArrowPatch.__init__(self,

Python 3d Pyramid

强颜欢笑 提交于 2019-12-22 10:04:13
问题 I'm new to 3d plotting. I just want to build a pyramid out of 5 Points and cut a plane through it. My problem is I don't know how to fill the sides. points = np.array([[-1, -1, -1], [1, -1, -1 ], [1, 1, -1], [-1, 1, -1], [0, 0 , 1]]) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') r = [-1,1] X, Y = np.meshgrid(r, r) ax.plot_surface(X,Y,-1, alpha=0.5) ax.plot_surface(X,Y,0.5, alpha=0.5, facecolors='r') ax.scatter3D(points[:, 0], points[:, 1], points[:, 2]) ax.set_xlabel('X') ax

Adding colors to a 3d quiver plot in matplotlib

风流意气都作罢 提交于 2019-12-22 04:57:11
问题 I want to have colors corresponding to a colormap in my 3d quiver plot. The 2d version of the plot has an optional array that is used to map colors to the arrows. How can I create the same effect in the 3d version? 回答1: 3D quiver plots are a brand-new feature in 1.4 it (and it's documentation) might still be a bit rough around the edges. In this case we can try to use the fact that the quiver is implemented as a LineCollection which (eventually) inherits from ScalarMappable which means it

Plotting a series of 2D plots projected in 3D in a perspectival way

旧巷老猫 提交于 2019-12-21 23:04:16
问题 I'd like to plot a likelihood distribution, basically an NxT matrix, where each row represents a distribution on some variable in each timestep t (t=0...T) , so I could visualize the trajectory which a Maximum Likelihood Estimation would yield. I imagine several 2D plots, one in front of the other - something like this: so far based on this I've tried: def TrajectoryPlot(P): P=P[0:4] fig = plt.figure() ax = fig.gca(projection='3d') def cc(arg): return colorConverter.to_rgba(arg, alpha=0.6) xs

Get data from mplot3d graph

北城以北 提交于 2019-12-20 05:47:07
问题 I can’t find out how to get data from an mplot3d graph. Something similar to the 2D style: line.get_xdata() Is it possible? 回答1: Line3D You can get get the original data from the (private) _verts3d attribute xdata, ydata, zdata = line._verts3d print(xdata) Complete example import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib.pyplot as plt mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() ax = fig.gca(projection='3d') # Prepare arrays x, y

Matplotlib 3d plot: how to get rid of the excessive white space?

≡放荡痞女 提交于 2019-12-19 12:22:05
问题 If I make a 3d plot in Matplotlib: from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.gca(projection='3d') x_labels = [10,20,30] x = [1,2,3,4] y = [3,1,5,1] legend = False for label in x_labels: x_3d = label*np.ones_like(x) ax.plot(x_3d, x, y, color='black', label='GMM') if legend == False: ax.legend() legend = True ax.set_zlabel('test') It will produce: The left side have excessive white space. I want to know if it is possible to get rid of it? 回答1: It's probably too late,

How do I crop an Axes3D plot with square aspect ratio?

倾然丶 夕夏残阳落幕 提交于 2019-12-19 05:05:05
问题 Here's a barebones example: import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() f = fig.add_subplot(2, 1, 1, projection='3d') t = fig.add_subplot(2, 1, 2, projection='3d') # axes for d in {f, t}: d.plot([-1, 1], [0, 0], [0, 0], color='k', alpha=0.8, lw=2) d.plot([0, 0], [-1, 1], [0, 0], color='k', alpha=0.8, lw=2) d.plot([0, 0], [0, 0], [-1, 1], color='k', alpha=0.8, lw=2) f.dist = t.dist = 5.2 # 10 is default plt.tight_layout() f.set_aspect('equal') t

Plotting 3D Polygons in Python 3

老子叫甜甜 提交于 2019-12-19 04:45:11
问题 In my quest to somehow get 3D polygons to actually plot, I came across the following script (EDIT: modified slightly): Plotting 3D Polygons in python-matplotlib from mpl_toolkits.mplot3d import Axes3D from matplotlib.collections import Poly3DCollection import matplotlib.pyplot as plt fig = plt.figure() ax = Axes3D(fig) x = [0,1,1,0] y = [0,0,1,1] z = [0,1,0,1] verts = [zip(x, y,z)] ax.add_collection3d(Poly3DCollection(verts),zs=z) plt.show() But when I run that, I get the following error

How to plot a 3D patch collection in matplotlib?

独自空忆成欢 提交于 2019-12-18 21:53:39
问题 I'm trying to make a 3D plot in matplotlib with three circles on it, each centered at the origin and with a radius of 1, pointing in different directions - to illustrate a sphere of radius 1, for example. In 2D I would make a circle patch collection and add it to the axes. In 3D I'm having trouble getting the patches to show up at all, let alone orient them in different directions. import matplotlib import matplotlib.pyplot as P import mpl_toolkits.mplot3d as M3 fig = P.figure() ax = fig.add

How to disable perspective in mplot3d?

允我心安 提交于 2019-12-18 02:45:54
问题 Is it possible to disable the perspective when plotting in mplot3d, i.e. to use the orthogonal projection? 回答1: Sort of, you can run this snippet of code before you plot: import numpy from mpl_toolkits.mplot3d import proj3d def orthogonal_proj(zfront, zback): a = (zfront+zback)/(zfront-zback) b = -2*(zfront*zback)/(zfront-zback) return numpy.array([[1,0,0,0], [0,1,0,0], [0,0,a,b], [0,0,0,zback]]) proj3d.persp_transformation = orthogonal_proj It is currently an open issue found here. 回答2: This