我画了两张等高线图,一张是用 matplotlib 画的,另一张是用plotly 画的。我想在图中添加更多等高线。对于 matplotlib,没有问题。但关于情节,我不知道如何改变轮廓线的数量。下面是我的代码。
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('seaborn')
import math
x = np.linspace(-np.pi, np.pi, num=50)
y = x
def pf(a, b):
return math.cos(b) / (1 + a**2)
f = np.empty((len(x), len(y)))
for i in range(len(x)):
for j in range(len(y)):
f[i,j] = pf(x[i], y[j])
# contour plot using matplotlib
cp = plt.contour(x, y, f, 45, cmap='viridis')
plt.clabel(cp, inline=1, fontsize=10);
Run Code Online (Sandbox Code Playgroud)
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Contour(z=f, x=x, y=y, contours_coloring='lines', line_width=1, …Run Code Online (Sandbox Code Playgroud)