Skip to content

Instantly share code, notes, and snippets.

@Mark24Code
Last active April 26, 2017 06:30
Show Gist options
  • Save Mark24Code/5e2b8dcf9f7de9224da8813028f65c8e to your computer and use it in GitHub Desktop.
Save Mark24Code/5e2b8dcf9f7de9224da8813028f65c8e to your computer and use it in GitHub Desktop.
绘制时间复杂度范围
import matplotlib.font_manager as fm
import numpy as np
import matplotlib.pyplot as plt
myfont = fm.FontProperties(fname='/Library/Fonts/Microsoft/Microsoft Yahei.ttf')
x = np.linspace(0,2,50)
y1 = x
y2 = np.log(x)
y3 = x*np.log(x)
y4 = x**2
y5 = x**3
y6 = 2**x
y7 = 3**x
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
#移动left轴和buttom轴
ax.spines['left'].set_position(('data', 0))
ax.spines['bottom'].set_position(('data', 0))
#隐藏right轴和top轴
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.plot(x,y1,label="$y=x$",color="red")
plt.plot(x,y2,label="$y=\ln {x}$",color="darkorange")
plt.plot(x,y3,label="$y=x\ln {x}$",color="olivedrab")
plt.plot(x,y4,'-.',label="$y=x^{2}$",color="darkseagreen")
plt.plot(x,y5,'-.',label="$y=x^{3}$",color="green")
plt.plot(x,y6,':',label="$y=2^{x}$",color="darkblue")
plt.plot(x,y7,':',label="$y=3^{x}$",color="deeppink")
plt.title('复杂度 分布',fontproperties=myfont)
# 图例
plt.legend(loc='upper right')
# x,y坐标范围
plt.xlim(0,2)
plt.ylim(-2,4)
# 辅助线
plt.axhline(1)
plt.axvline(1)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment