python - 如何修复此图表不知道出了什么问题
问题描述
我想我的代码是正确的,但是图形的输出似乎不正确
from numpy import exp,arange
from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show
import matplotlib.pyplot as plt
import numpy as np
import math
# the function that I'm going to plot
def z_func(x,y):
return (1+(2*(np.cos(x)**2 * (x))+4 * (y)*(np.sqrt(1-y**2))*(np.cos(x))*(np.sin(x))))
x = arange(-3.0,3.0,0.1)
y = arange(-3.0,3.0,0.1)
X,Y = meshgrid(x, y) # grid of point
Z = z_func(X, Y) # evaluation of the function on the grid
im = imshow(Z,cmap=cm.RdBu) # drawing the function
# adding the Contour lines with labels
cset = contour(Z,arange(-1,1.5,0.2),linewidths=2,cmap=cm.Set2)
clabel(cset,inline=True,fmt='%1.1f',fontsize=10)
colorbar(im) # adding the colourbar
# latex fashion title
title('$win$')
show()
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
cmap=cm.RdBu,linewidth=0, antialiased=False)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
解决方案
推荐阅读
- build - hiddenapi 上 SIGILL 的 AOSP9.0 构建失败
- java - 当我收到错误“错误:'size_t'没有命名类型”时,如何让源媒体安装 Apache Accumulo?
- python - 将包含表情符号的 JSON 读入 Pandas 数据框
- amazon-web-services - 在关闭之前将 docker 日志从 ec2 实例上传到 S3
- three.js - 三.RGBELoader() HDR曝光不改变
- gtk3 - 如何让 gtk3 自定义按钮字体、背景和前景色?
- jquery - AJAX:未捕获的 ReferenceError:未为单个 HTML 中多个 Web 表单中的多个条目定义 $
- javascript - 使用 Js / Javascript 调整浏览器大小添加事件宽度 min-max
- ios - UIAlertController 文本字段没有得到输入
- python - Django 2.1:是否可以在电子邮件中包含 Ngrok 的域而不是本地主机的域?