随笔 - 402  文章 - 1 评论 - 20 阅读 - 113万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

Matplotlib发布新版本3.1,新版本带来了那些新的功能和特性。

Axes3D.voxels对结果voxels进行着色,voxels()方法默认shade参数改True。它会根据方向调整阴影,其行为与trisurf()以及bar3d()的匹配参数相同。

示例代码:

复制代码
示例代码:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x, y, z = np.indices((8, 8, 8))
cube1 = (x < 3) & (y < 3) & (z < 3)
cube2 = (x >= 5) & (y >= 5) & (z >= 5)
link = abs(x - y) + abs(y - z) + abs(z - x) <= 2
voxels = cube1 | cube2 | link
colors = np.empty(voxels.shape, dtype=object)
colors[link] = 'red'
colors[cube1] = 'blue'
colors[cube2] = 'green'
fig = plt.figure(figsize=plt.figaspect(0.5))
ax, ax_shaded = fig.subplots(1, 2, subplot_kw=dict(projection='3d'))
ax.voxels(voxels, facecolors=colors, edgecolor='k', shade=False)
ax.set_title("Unshaded")
ax_shaded.voxels(voxels, facecolors=colors, edgecolor='k', shade=True)
ax_shaded.set_title("Shaded (default)")
plt.show()
复制代码

 

posted on   chamie  阅读(921)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示