import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname='C:\Windows\Fonts\simfang.ttf')
x = np.linspace(-2,2,100)
y = x**2
z = np.sqrt(4-x**2)
fix,ax = plt.subplots()
ax.plot(x,y,label="$y=x^2$",color="red",linewidth = 2)
ax.plot(x,z,label="&x^2+y^2=4$",linewidth = 2)
ax.plot(x,-z,label="$x^2+y^2=4$",linewidth = 2)
ax.set_title("线性图",fontsize = 24,fontproperties=font)
ax.set_xlabel("X轴",fontsize = 20,fontproperties=font)
ax.set_ylabel("Y轴",fontsize = 20,fontproperties=font)
plt.legend
plt.grid()
plt.show()
运行画出的图像为:
第二个画图代码:
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.axisartist as axisartist
fig = plt.figure(figsize=(6,6))
ax = axisartist.Subplot(fig,111)
fig.add_axes(ax)
ax.axis[:].set_visible(False)
ax.axis['x'] = ax.new_floating_axis(0,0)
ax.axis['y'] = ax.new_floating_axis(1,0)
ax.axis['x'].set_axisline_style('-|>',size=1.0)
ax.axis['y'].set_axisline_style('-|>',size=1.0)
ax.axis['x'].set_axis_direction('top')
ax.axis['y'].set_axis_direction('right')
plt.xlim(-10,10)
plt.ylim(-0.1,1.2)
x = np.arange(-10,10,0.1)
y = 1/(1+np.exp(-x))
plt.plot(x,y,label=r"$sigmoid=\frac{1}{1+e^{-x}}$",c='r')
plt.legend()
运行画出的图像为:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)