有没有办法在 sympy plot3d 绘图上放置颜色条? [英] Is there a way to put a color bar on a sympy plot3d plot?

查看:23
本文介绍了有没有办法在 sympy plot3d 绘图上放置颜色条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个 3d 图,我从文档中说明的 sympy 符号中构建,让我们说代码是

from sympy 导入符号从 sympy.plotting 导入 plot3dx, y = 符号('x y')plot3d(x*y, (x, -5, 5), (y, -5, 5))

如何将颜色条附加到它?

解决方案

使用来自

So I have a 3d plot that I bulit from sympy symbols as ilustrated in the docs let us say the code is

from sympy import symbols
from sympy.plotting import plot3d
x, y = symbols('x y')
plot3d(x*y, (x, -5, 5), (y, -5, 5))

how do I attach a colorbar to it?

解决方案

Using the code from this post you could move the plot to matplotlib and draw the colorbar with matplotlib:

from sympy import symbols
from sympy.plotting import plot3d
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

x, y = symbols('x y')
plot1 = plot3d(x*y, (x, -5, 5), (y, -5, 5), show=False)

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

backend = plot1.backend(plot1)
backend.ax = ax
backend._process_series(backend.parent._series, ax, backend.parent)
plt.close(backend.fig)
ax.collections[0].set_cmap('inferno') # optionally change the colormap
plt.colorbar(ax.collections[0])
plt.show()

这篇关于有没有办法在 sympy plot3d 绘图上放置颜色条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆