本文整理汇总了Python中mpl_toolkits.mplot3d.proj3d.proj_transform函数的典型用法代码示例。如果您正苦于以下问题:Python proj_transform函数的具体用法?Python proj_transform怎么用?Python proj_transform使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了proj_transform函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_function_and_solution
def plot_function_and_solution(func, area, first_point, solution, meshgrid):
fig = plt.figure(figsize=(14, 8))
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122, projection="3d")
fig.suptitle("My Function", size=24)
# Color mesh
ax1.set_axis_bgcolor("white")
# ax1.pcolormesh(X, Y, Z, cmap=cm.jet, norm=LogNorm())
ax1.contour(*meshgrid, zdir='z', offset=0, stride=0.1, cmap=cm.coolwarm)
ax1.scatter(*first_point, color="k")
ax1.annotate('First Point', xy=first_point, xytext=(-0.5, 1.25),
arrowprops=dict(facecolor='black', shrink=0.05))
ax1.scatter(solution[0], solution[1], color="g")
ax1.annotate('Solution', xy=(solution[0], solution[1]), xytext=(-1, -3),
arrowprops=dict(facecolor='blue', shrink=0.05))
# Surface plot
ax2.set_axis_bgcolor("white")
ax2.plot_surface(*meshgrid, norm = LogNorm(), cmap=cm.jet, linewidth=1)
first_point_3d = (first_point[0], first_point[1], func(first_point))
ax2.view_init(azim=65, elev=25)
ax2.scatter(*first_point_3d, color="k")
xa, ya, _ = proj3d.proj_transform(first_point_3d[0], first_point_3d[1], first_point_3d[2], ax2.get_proj())
ax2.annotate("First Point", xy = (xa, ya), xytext = (20, 120),
textcoords = 'offset points', ha = 'right', va = 'bottom',
arrowprops=dict(facecolor='black', shrink=0.05))
ax2.scatter(*solution, color="k")
xa, ya, _ = proj3d.proj_transform(solution[0], solution[1], solution[2], ax2.get_proj())
ax2.annotate("Solution", xy = (xa, ya), xytext = (0, 100),
textcoords = 'offset points', ha = 'right', va = 'bottom',
arrowprops=dict(facecolor='blue', shrink=0.05))
示例2: refresh
def refresh(self):
for l in self._labs:
x, y, _ = proj3d.proj_transform(l[1][0], l[1][1], l[1][2], self.ax1.get_proj())
x2, y2, _ = proj3d.proj_transform(l[2][0], l[2][1], l[2][2], self.ax1.get_proj())
l[0].xytext = self._midp(x, y, x2, y2)
for l in self._alabs:
x, y, _ = proj3d.proj_transform(l[1][0], l[1][1], l[1][2], self.ax1.get_proj())
l[0].xytext = (x+0.002,y+0.002)
self.canvas.draw()
示例3: plot_surface
def plot_surface(ax, m, start, goal, title):
t1 = np.arange(181)
t2 = np.arange(361)
X, Y = np.meshgrid(t1, t2, indexing='ij')
surf = ax.plot_surface(X, Y, m, cmap=cm.jet)
ax.set_title(title)
ax.set_xlabel('theta1')
ax.set_ylabel('theta2')
x, y, _ = proj3d.proj_transform(start[0],start[1],m[start[0], start[1]], ax.get_proj())
x2, y2, _ = proj3d.proj_transform(goal[0],goal[1],m[goal[0], goal[1]], ax.get_proj())
l1 = ax.annotate('start', xy=(x, y))
l2 = ax.annotate('goal', xy=(x2, y2))
示例4: update_position
def update_position(e):
for i, x, y, z, l in zip(i_s, xs, ys, zs, labels):
x2, y2, _ = proj3d.proj_transform(x, y, z, ax.get_proj())
l.xy = x2,y2
l.update_positions(fig.canvas.renderer)
fig.canvas.draw()
示例5: update_position
def update_position(e):
for a in range(len(all_position)):
x2, y2, _ = proj3d.proj_transform(all_position[a][0],all_position[a][1],all_position[a][2], ax.get_proj())
all_label[a].xy = x2,y2
label.update_positions(fig.canvas.renderer)
fig.canvas.draw()
示例6: annotatePlot
def annotatePlot(X, index, annotes, button):
"""Create popover label in 3d chart
Args:
X (np.array) - array of points, of shape (numPoints, 3)
index (int) - index (into points array X) of item which should be printed
Returns:
None
"""
# If we have previously displayed another label, remove it first
if hasattr(annotatePlot, 'label'):
annotatePlot.label.remove()
if button == 2:
# Get data point from array of points X, at position index
x2, y2, _ = proj3d.proj_transform(X[index, 0], X[index, 1], X[index, 2], ax.get_proj())
annote = annotes[index]
annotatePlot.label = plt.annotate(annote,
xy=(x2, y2), xytext=(-20, 20), textcoords='offset points', ha='right',
va='bottom',
bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),
arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0'))
# if we press another button (i.e. to pan the axis we need to create a dummy (blank) annotate
# this is because the annotePlot still has an attribute (it has previously been called
elif button != 2:
annotatePlot.label = plt.annotate('', xy=(0, 0), xytext=(0, 0))
fig.canvas.draw()
示例7: draw
def draw(self, renderer):
#xs3d, ys3d, zs3d = self._verts3d
for coords in self._verts3d:
xs3d, ys3d, zs3d = coords[0], coords[1], coords[2]
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
FancyArrowPatch.draw(self, renderer)
示例8: LabelEvent
def LabelEvent(self, GraphicsObject, PlotOptions):
EventTypeFormatted = self.EventType
if EventTypeFormatted == 'upwr_flyby':
EventTypeFormatted = 'unpowered flyby'
elif EventTypeFormatted == 'pwr_flyby':
EventTypeFormatted = 'powered flyby'
elif EventTypeFormatted == 'chem_burn':
EventTypeFormatted = 'chemical burn'
elif EventTypeFormatted == 'LT_rndzvs':
EventTypeFormatted = 'LT rendezvous'
elif EventTypeFormatted == 'begin_spiral':
EventTypeFormatted = 'begin spiral'
elif EventTypeFormatted == 'end_spiral':
EventTypeFormatted = 'end spiral'
description = EventTypeFormatted + '\n' + self.Location + '\n' + self.GregorianDate
#for launches a C3 and DLA are needed
if self.EventType == 'launch':
description += '\nC3 = ' + "{0:.3f}".format(self.C3) + ' $km^2/s^2$'
#add the LV to the description?
description += '\nDLA = ' + "{0:.1f}".format(self.Declination) + '$^{\circ}$'
#for non-launch departures only the C3 is needed
if self.EventType == 'departure':
description += '\nC3 = ' + "{0:.3f}".format(self.C3) + ' $km^2/s^2$'
#for spirals output only the delta-v
if self.EventType == 'begin_spiral' or self.EventType == 'end_spiral':
description += '\n$\Delta v$ = ' + "{0:.3f}".format(self.DVmagorThrottle) + ' $km/s$'
#for other events, output v-infinity and DLA
if self.EventType == 'upwr_flyby' or self.EventType == 'pwr_flyby' or self.EventType == 'intercept' or self.EventType == 'interface' or self.EventType == 'insertion':
description += '\n$v_\infty$ = ' + "{0:.3f}".format(math.sqrt(self.C3)) + ' $km/s$'
description += '\nDEC = ' + "{0:.1f}".format(self.Declination) + '$^{\circ}$'
#for flybys, altitude should be outputed
if self.EventType == 'upwr_flyby' or self.EventType == 'pwr_flyby':
description += '\naltitude = ' + "{0:.0f}".format(self.Altitude) + ' $km$'
#for propulsive events, a deltaV is needed
if self.EventType == 'departure' or self.EventType == 'pwr_flyby' or self.EventType == 'insertion' or self.EventType == 'chem_burn' or self.EventType == 'rendezvous':
description += '\n$\Delta v$ = ' + "{0:.3f}".format(self.DVmagorThrottle) + ' $km/s$'
#always append the spacecraft Mass
description += '\nm = ' + "{0:.0f}".format(self.Mass) + ' $kg$'
#draw the text
#note, do not draw anything for chemical burns below 10 m/s
if not (self.EventType == "chem_burn" and self.DVmagorThrottle < 0.001):
x2D, y2D, _ = proj3d.proj_transform(self.SpacecraftState[0],self.SpacecraftState[1],self.SpacecraftState[2], GraphicsObject.get_proj())
self.eventlabel = plt.annotate(description, xycoords = 'data', xy = (x2D, y2D), xytext = (20, 20), textcoords = 'offset points', ha = 'left', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.5', fc = 'white', alpha = 0.5), arrowprops = dict(arrowstyle = '->',
connectionstyle = 'arc3,rad=0'), size=PlotOptions.FontSize)
self.AnnotationHelper = self.eventlabel.draggable(use_blit=True)
self.pcid = GraphicsObject.figure.canvas.mpl_connect('button_press_event', self.ClickAnnotation)
self.rcid = GraphicsObject.figure.canvas.mpl_connect('button_release_event', self.ReleaseAnnotation)
示例9: plot_emotions
def plot_emotions(emotions, X, Y, Z, plot_labels = True):
emos = emotions
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d import proj3d
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X, Y, Z)
ax.set_xlabel('Serotonin')
ax.set_ylabel('Noradrenaline')
ax.set_zlabel('Dopamine')
if plot_labels:
labels = []
for i in range(len(X)):
x2, y2, _ = proj3d.proj_transform(X[i],Y[i],Z[i], ax.get_proj())
label = plt.annotate(
emos[i],
xy = (x2, y2), xytext = (-5, 5),
textcoords = 'offset points', ha = 'right', va = 'bottom',
bbox = dict(boxstyle = 'round,pad=0.1', fc = 'yellow', alpha = 0.5),
arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
labels.append(label)
def update_position(e):
for i in range(len(X)):
x2, y2, _ = proj3d.proj_transform(X[i],Y[i],Z[i], ax.get_proj())
labels[i].xy = (x2, y2)
labels[i].update_positions(fig.canvas.renderer)
fig.canvas.draw()
fig.canvas.mpl_connect('button_release_event', update_position)
plt.tight_layout()
plt.show()
示例10: draw
def draw(self, renderer):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
xs3d, ys3d, zs3d = self._verts3d
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
FancyArrowPatch.draw(self, renderer)
示例11: annotatedScatter3d
def annotatedScatter3d(labels,xs,ys,zs):
"""3d scatter plot, sadly rotating breaks the association of dots and annotations"""
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
sc = ax.scatter(xs,ys,zs)
for txt, x, y, z in zip(labels, xs, ys, zs):
x2, y2, _ = proj3d.proj_transform(x,y,z, ax.get_proj())
label = plt.annotate(txt, xy = (x2, y2))
示例12: draw
def draw(self, renderer):
xs3d, ys3d, zs3d = self._verts3d
xs, ys, zs = proj3d.proj_transform(xs3d,
ys3d,
zs3d,
renderer.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
mp.FancyArrowPatch.draw(self, renderer)
示例13: update_position
def update_position(e):
global fig
global ax
global labels_and_points
for label, x, y, z in labels_and_points:
x2, y2, _ = proj3d.proj_transform(x, y, z, ax.get_proj())
label.xy = x2,y2
label.update_positions(fig.canvas.renderer)
fig.canvas.draw()
示例14: update_position
def update_position(e):
print "In update"
x2, y2, _ = proj3d.proj_transform(x, y, z, ax.get_proj())
for i in range(0, np.size(z)):
if i % 800 == 0:
labels[(i / 800)].xy = x2[i], y2[i]
labels[(i / 800)].update_positions(fig.canvas.renderer)
fig.canvas.draw()
示例15: update_position
def update_position(e):
x2, y2, _ = proj3d.proj_transform(data3N[:, 0], data3N[:, 1],
data3N[:, 2], ax.get_proj())
for i in range(len(data3N[:, 0])):
label = Labels[i]
label.xy = x2[i],y2[i]
label.update_positions(fig.canvas.renderer)
fig.canvas.draw()