- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Matplotlib 设计三维插图。一切都很好,除了(红色)参数曲线得到错误的 zorder 而(绿色)参数曲面完全正确绘制。
由以下代码生成的输出:
我知道 Matplotlib 在精确计算对象的 zorder 方面的能力有限,但由于它可以为参数化表面做到这一点,所以它似乎是 Matplotlib 中的一个错误。
就是说,是否有任何方法可以强制执行正确的 z 顺序以使事情快速进行?似乎我只能说,正确的透明蓝色平面位于其他一切之上。但是,将 zorder 参数放入 PolyCollection 似乎没有任何效果,将显式 zorder 参数放入绘制读取线的 plot 函数将弄乱其相对于绿色表面的顺序。
有没有办法强制将正确的蓝色透明表面置于所有内容之上?这是我到目前为止的代码:
#!/bin/env python3
from pylab import *
from mpl_toolkits.mplot3d import *
from matplotlib.collections import PolyCollection
from matplotlib.colors import colorConverter
from matplotlib.patches import FancyArrowPatch
rc('text', usetex=True)
rc('font', size=20)
fig = figure(figsize=(11,6))
ax = fig.gca(projection='3d')
ax.set_axis_off()
def f(x,t):
return t/2 * 0.55*(sin(2*x)+0.4*x**2-0.65)
c_plane = colorConverter.to_rgba('b', alpha=0.15)
N = 50
y = linspace(-1,1,N)
t = linspace(0,2,N)
yy, tt = meshgrid(y, t)
zz = f(yy,tt)
ax.plot(0*ones(y.shape), y, f(y,0), '-g', linewidth=3)
ax.plot(2*ones(y.shape), y, f(y,2), '-g', linewidth=3)
yt = 0.7*y
zt = f(yt, t) + 0.2*t
ax.plot(t, yt, zt, '-r', linewidth=3)
ax.plot((0,2), (yt[0], yt[-1]), (zt[0], zt[-1]), 'or')
ax.plot([2,2,2], [-1,yt[-1],yt[-1]], [zt[-1],zt[-1],-1], 'k--')
ax.plot(2*ones(y.shape), yt, f(yt,2)+0.1*(y+1), 'g:', linewidth=2)
ax.plot((2,2),
(yt[0], yt[-1]),
(f(yt[0], 2), f(yt[-1], 2) + 0.1*(y[-1]+1)), 'og')
ax.plot((0,2,2),
(-1,-1,zt[-1]),
(0,yt[-1],-1), 'ok')
ax.text(0, -1.1, 0, r'$p(0)=0$', ha='right', va='center')
ax.text(2, -1.05, zt[-1], r'$p(T)$', ha='right', va='center')
ax.text(0, -1.0, 1, r'$p$', ha='right', va='bottom')
ax.text(0, 1, -1.1, r'$q$', ha='center', va='top')
ax.text(0, -1, -1.1, r'$t=0$', ha='right', va='top')
ax.text(2, -1, -1.1, r'$t=T$', ha='right', va='top')
ax.text(2, yt[-1]-0.05, -1.05, r'$q(T)=q^*$', ha='left', va='top')
ax.text(0, 0.5, 0.05, r'$\mathcal{M}(0)$', ha='center', va='bottom')
ax.text(2, 0.1, -0.8, r'$\mathcal{M}(T)$', ha='center', va='bottom')
arrowprops = dict(mutation_scale=20,
linewidth=2,
arrowstyle='-|>',
color='k')
# For arrows, see
# https://stackoverflow.com/questions/29188612/arrows-in-matplotlib-using-mplot3d
class Arrow3D(FancyArrowPatch):
def __init__(self, xs, ys, zs, *args, **kwargs):
FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs)
self._verts3d = xs, ys, zs
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]))
FancyArrowPatch.draw(self, renderer)
a = Arrow3D([0,2], [-1,-1], [-1,-1], **arrowprops)
ax.add_artist(a)
a = Arrow3D([0,0], [-1,-1], [-1,1], **arrowprops)
ax.add_artist(a)
a = Arrow3D([0,0], [-1,1], [-1,-1], **arrowprops)
ax.add_artist(a)
# For surface illumination, see
# http://physicalmodelingwithpython.blogspot.de/2015/08/illuminating-surface-plots.html
# Get lighting object for shading surface plots.
from matplotlib.colors import LightSource
# Get colormaps to use with lighting object.
from matplotlib import cm
# Create an instance of a LightSource and use it to illuminate the surface.
light = LightSource(70, -120)
white = np.ones((zz.shape[0], zz.shape[1], 3))
illuminated_surface = light.shade_rgb(white*(0,1,0), zz)
ax.plot_surface(tt, yy, zz,
cstride=1, rstride=1,
alpha=0.3, facecolors=illuminated_surface,
linewidth=0)
verts = [array([(-1,-1), (-1,1), (1,1), (1,-1), (-1,-1)])]
poly = PolyCollection(verts, facecolors=c_plane)
ax.add_collection3d(poly, zs=[0], zdir='x')
poly = PolyCollection(verts, facecolors=c_plane)
ax.add_collection3d(poly, zs=[2], zdir='x')
ax.set_xlim3d(0, 2)
ax.view_init(elev=18, azim=-54)
show()
最佳答案
在 Matplotlib 3.5.0 中添加了使用 axis3d 更改绘图顺序的方法。 将参数 'computed_zorder' 设置为 False 允许手动控制绘图顺序
ax = plt.axes(projection='3d',computed_zorder=False)
ax.plot_surface(X1, Y1, Z1,zorder=4.4)
ax.plot_surface(X2, Y2, Z2,zorder=4.5)
较高的“zorders”绘制在顶部。一些常见的艺术家 z 顺序(这样你就不会在你的图例上绘制):
来自: https://matplotlib.org/stable/gallery/misc/zorder_demo.html
来源:https://github.com/matplotlib/matplotlib/commit/2db6a0429af47102456366f8d3a4df24352b252e(来自:https://github.com/matplotlib/matplotlib/pull/14508)
关于python - Matplotlib 中的 3D 参数化曲线不遵循 zorder。解决方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37611023/
有人知道让 zOrder 以不同方式处理视觉事件和鼠标事件的方法吗? 我有一个 我在 zOrder 中放置较高的元素,它稍微透明以突出显示某些内容,但它干扰了 :hover原始元素上的 css 样式。
看来 WindowsFormsHost 控件设置为显示在顶部。有什么方法可以更改其 z 顺序以允许同一窗口上的其他 WPF 控件在 WindowsFormsHost 控件顶部可见? 最佳答案 不幸的是
窗口的 z 顺序指示窗口在重叠窗口堆栈中的位置。 如果您使用双显示器,每个显示器是否都有自己的 z 顺序? 最佳答案 没有。每个显示器具有单独的 Z 顺序会导致在显示器之间移动窗口或窗口与多个显示器重
我正在尝试使用 View 翻转器为 2 个 View 之间的转换设置动画。看起来,默认情况下,ViewFlipper 将 Out 动画按 Z 顺序放置在 In 动画上方。有没有办法让传入的动画显示在传
我正在使用 WPF 弹出窗口,但它会在我桌面上的每个窗口上方弹出,即使我的应用程序已最小化也是如此。我怎样才能让它只停留在它起源的窗口上?当我的窗口在其他窗口后面时,也会发生同样的事情:弹出窗口显示在
我正在尝试使用 pyplot 的 funcanimation 为同一图中的不同对象设置动画。 它的工作方式几乎和我预期的一样,除了不同元素的显示顺序不同。所以绘图曲线、文本和图例显示在图像后面几乎看不
我有一个垂直 UIStackView 的逻辑: stackView.addArrangedSubview(v1) stackView.addArrangedSubview(v3) //later st
这是一个重现我的问题的例子: import matplotlib.pyplot as plt import numpy as np data1,data2,data3,data4 = np.rando
我有一些布局可以在 API 19: 4.2.2 上正常工作,但不能让它在 API 21: 5.0.1 上工作。 这是布局: 非常简单的东西。我只希望 textview 位于相
寻找一种在任何窗口 ZOrder 更改时得到通知的方法? Zorder 指的是窗口的分层。 0 的 zorder 在底部。我不知道还有什么其他方式可以问这个问题。 这适用于 Windows XP 或更
我需要使用 cartopy 生成 map 并在其上绘制一些数据(使用 networkx)。我能够做到,但 networkx 对象位于 map 后面。我正在尝试使用 zorder 强制图层的顺序,但是.
我有一个 Altair 图,其中多个点位于相似的 xy 位置,类似于 this plot在 Altair 教程中。由于我使用工具提示,我希望所选点上升到顶部(即增加 matplotlib 术语中的 z
下面的代码包含一个简单的网格,在网格的中间列中有一个按钮。按钮宽度(有意地)大于放置它的列。请注意,按钮的左侧部分可见,右侧部分不可见。我需要做什么才能让左右按钮部分不可见?按钮的右侧部分位于右侧网格
1) 我需要 Matplotlib 中似乎不存在的屏蔽功能。(如果情况并非如此,请告诉我)。 2) Matplotlib 具有裁剪功能,但“裁剪”出的区域使用相同的 zorder,因此渲染几个重叠的多
我正在使用 matplotlib 饼图:https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.pie.html . 我正在生成一个使用这些饼图
我正在一对双轴 (twinx) 上绘制一系列线条。我可以使用 zorder 参数控制哪些线在每个轴的“顶部”,我可以使用 Axes.set_zorder()< 设置哪个轴(作为一个整体)在顶部 功能
我使用 jquery ui 来显示菜单。在这个网页上,有一些图片,菜单显示在图片后面。 我已经试过了: .ui-menu { z-index: 9999999; } 或 #menu { z-index
我有 3 个轴,一条或多条线。由于获得了光标所在行的选择器,我尝试更改包含该行的斧头的 zorder。 精度:我在 FigureCanvasQTAgg 派生对象中 def onmove(self, e
我遇到了一个相当奇怪的图例行为和错误栏绘图命令。我正在使用 Python xy 2.7.3.1 和 matplotlib 1.1.1下面的代码举例说明了观察到的行为: import pylab as
在将具有不同 y 轴的多个错误栏绘制到一个子图中时,我目前正在处理 matplotlib 的一些奇怪行为。 这样做时,对应于第二个误差线图的网格总是与第一个误差线图重叠。使用 zorder 选项,我只
我是一名优秀的程序员,十分优秀!