小编Ann*_*ika的帖子

mplot3d轴限制与墙壁不对应

我试图在mplot3d图中创建一个接触所有轴墙的平面.轴限制使用ax.set_xlim(-6.0,6.0)或设置ax,set_xlim3d(-6.0,6.0).在这两种情况下,墙壁都略微超出规定的限制.使用Poly3DCollection平面绘制平面绘制我的平面但是,它不会触及轴墙.

我正在使用(网格和墙壁的颜色设置作为我的屏幕上的默认颜色,至少看起来很轻,因此模糊了"功能")

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')

ax.set_xlim(-6.0, 6.0)
ax.set_ylim(-6.0, 6.0)
ax.set_zlim(-1.0, 1.0)

ax.w_xaxis.set_pane_color((.85, .85, .85, 1.0))
ax.w_yaxis.set_pane_color((.85, .85, .85, 1.0))
ax.w_zaxis.set_pane_color((.85, .85, .85, 1.0))

ax.w_xaxis._axinfo.update({"grid": {"color": (.7, .7, .7, 1)}})
ax.w_yaxis._axinfo.update({"grid": {"color": (.7, .7, .7, 1)}})
ax.w_zaxis._axinfo.update({"grid": {"color": (.7, .7, .7, 1)}})

x = [-6,6,6,-6]
y = [-6,-6,6,6]
z = [0,0,0,0]

verts = [zip(x,y,z)]
collection = Poly3DCollection(verts)
collection.set_color("green")
ax.add_collection3d(collection)

plt.tight_layout() …
Run Code Online (Sandbox Code Playgroud)

python matplotlib mplot3d

5
推荐指数
0
解决办法
79
查看次数

mplot3D fill_between 超出轴限制

我有一些与使用 mplot3D 在 Python 中创建简单线图相关的问题,其中填充了图下方的区域。我在 RedHatEnterprise 7.2、matplotlib 1.2.0 和 numpy 1.7.2 上使用 Python 2.7.5。

使用下面的代码,我可以生成线图。这按预期显示,绘图的开始/结束由导入的数据集的限制设置。

然后,我尝试使用 Bart 从Plotting a series of 2D plots in a perspectival way 中给出的答案填充线图和 -0.1 之间的区域。然而,这是有效的,填充区域继续超出数据集的限制。从链接运行示例时也是如此。

此屏幕截图显示了填充区域超出设置的轴限制生成的绘图。 生成的绘图填充区域超出了设置的轴限制。

  1. 我如何实现填充区域只是数据集的范围或轴限制,以较小者为准?
  2. 如何将这些图的图例添加到图中?

代码如下:

from numpy import *
import matplotlib.pylab as plt
from mpl_toolkits.mplot3d import Axes3D

x,y = genfromtxt("data.dat",unpack=True)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ax.add_collection3d(plt.fill_between(x,y,-0.1, color='orange', alpha=0.3,label="filled plot"),1, zdir='y')

ax.plot(x,y,1,zdir="y",label="line plot")
ax.legend()

ax.set_xlim3d(852.353,852.359)
ax.set_zlim3d(-0.1,5)
ax.set_ylim3d(0,2)
ax.get_xaxis().get_major_formatter().set_useOffset(False)

plt.show()
Run Code Online (Sandbox Code Playgroud)

python matplotlib mplot3d

4
推荐指数
1
解决办法
3112
查看次数

标签 统计

matplotlib ×2

mplot3d ×2

python ×2