numpy 如何在图形上绘制渐变色图案?

rsl1atfo  于 2023-06-29  发布在  其他
关注(0)|答案(1)|浏览(97)

我要用彩色图表画一个图。但我做的图表不是渐变颜色模式。
你知道怎么修吗?

import numpy as np
import matplotlib.pyplot as plt

def f(x, y):
  return -2*np.cos(8*np.pi*x/0.8)*np.cos(2*np.pi*(y+0.4)/0.8) -2*np.cos(6*np.pi*x/0.8)*np.cos(4*np.pi*(y+0.4)/0.8)

x = np.linspace(0, 0.8, 100)
y = np.linspace(-0.4, 0.4, 100)

X, Y = np.meshgrid(x, y)
Z= f(X, Y)

fig,ax=plt.subplots(1,1)
cp = ax.contourf(X, Y, Z, rstride=1, cstride=1,cmap='jet')
ax.set_box_aspect(1)
plt.axis('off')
plt.show()

the graph I made it
the ideal graph I want to makethe source

5lhxktic

5lhxktic1#

您可以使用 contourf 的levels参数,如下所示:

cp = ax.contourf(X, Y, Z, rstride=1, cstride=1,cmap='jet',levels=100)

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contourf.html

相关问题