二维图
代码:
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(-1.00,1.00,100)
cond=[True if (i>=0 and i<0.5) else False for i in x]
y=(-2)*x*(x<0)+(-(np.e**(-(np.abs(x))))+1)*cond+np.abs(x)*np.log10(2)*(x<=0.5)
plt.ylim(0,2)
plt.xlim(-1,1)
plt.plot(x,y)
plt.show()
print('asdfg')
图像:
三维图(未完成)
代码:
import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D X = np.arange(-1, 1, 0.01) Y = np.arange(-1, 1, 0.01) X, Y = np.meshgrid(X, Y) figure = plt.figure() ax = Axes3D(figure) X = np.arange(-1, 1, 0.01) Y = np.arange(-1, 1, 0.01) X, Y = np.meshgrid(X, Y)
图像:
代码(借鉴于大数据八班何洪涛同学):
mport numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D # fun函数: # # 当(x,y)距原点小于0.5,返回圆锥上此点z值,根据图形判断是圆锥(求z的值是查的公式) # # 否则,返回距原点的距离 def fun(i, j): if i**2+j**2 < 0.25: return (i**2+j**2)**0.5*(2**0.5)*2 return (i**2+j**2)**0.5 fig1 = plt.figure() #创建一个3D图像 ax = Axes3D(fig1) X = np.arange(-1, 1, 0.01) Y = np.arange(-1, 1, 0.01) # 设置x与y的取值范围以及样点 x = list(X) y = list(Y) # 为Z赋值 for i in range(200): for j in range(200): Z[i][j] = fun(x[i],y[j]) #将i,j在x,y中进行检索。 Z = np.array(Z) X, Y = np.meshgrid(X, Y)# 生成网格。 ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='rainbow' alpha=0.5) plt.show() #设置x,y的长度 rainbow是用来调用颜色的 alpha 表示透明度。
图像(借鉴与大数据八班何洪涛同学):
何洪涛同学博客网址http://blog.sina.cn/dpool/blog/u/6752390419#type=-1
