원 그래프

설문조사의 결과를 원그래프로 나타낸 파일

 

import matplotlib.pyplot as plt
import matplotlib as mpl
plt.rc('font',family='HysanB') #한글 폰트 깨짐방지
mpl.rcParams['font.size'] =20.0
labels='월 1회 퇴사','월 2회 퇴사','현행 유지','기타'
sizes=[24.2,14.5,54,7.3]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral','lightcyan','lightpink']
explode = (0,0,0.1,0)  # only "explode" the 2nd slice (i.e. 'Hogs')
plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90)
plt.axis('equal')
import numpy as np
plt.show()

fi

Gradient 와 함수

import matplotlib
import numpy as np

import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z=X**2-Y**2+Y
U=2*X
V=-2*Y+1
origin = 'lower'

plt.figure()
plt.streamplot(X, Y, U, V, color='blue')
plt.title('Simplest default with labels')
CS = plt.contourf(X, Y, Z,
                  alpha=0.5,
                  cmap=plt.cm.coolwarm)
cbar = plt.colorbar(CS)
cbar.ax.set_ylabel('verbosity coefficient')
plt.show()
con2

함수의 그레디언트는 그 함수의 등위면에 수직이다.

 

3차원 그래프와 2차원 등고선

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x= np.arange(-100,100,1)
y= np.arange(-100,100,1)
X,Y=np.meshgrid(x,y)
Z=X**2-Y**2+Y
v=[100*i for i in range(100)]
cset1 = ax.contour(X, Y, Z,zdir='z',offset=10000,color='blue')
cset = ax.contour(X, Y, Z,v,cmap=cm.coolwarm,alpha=0.3)
ax.set_xlabel('X')
ax.set_xlim(-100, 100)
ax.set_ylabel('Y')
ax.set_ylim(-100, 100)
ax.set_zlabel('Z')
ax.set_zlim(0, 10000)
ax.clabel(cset1, fontsize=10, inline=1)

plt.show()

cont

3차원 그래프에 등고선을 넣는 예제

수열의 수렴성

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

x = np.arange(1, 50, 1)
x1 = np.arange(1, 20, 1)

x2= np.arange(20, 50, 1)
y = 1/x
y1=1/x1
y2=1/x2
y3=1/x**2
Z=x*0
Z1=x*0-0.05



z=np.linspace(0,0,49)

name_list=(0,10,20,30,40,50)
pos_list=(0,10,20,30,40,50)
ax=plt.axes()
plt.ylim(-0.1,1.1)
plt.xlim(0,50)

# plt.scatter(x,y,c='blue',label=r"$\frac{1}{n}$")
plt.scatter(x1,y1,c='blue')
plt.scatter(x2,y2,c='red')
plt.scatter(x,y3,c='black')



plt.plot(x,Z1,c="gray",lw=1.5)
plt.plot(x,-Z1,c="gray",lw=1.5)

plt.grid(True,lw=1,ls="--",c='.75')
plt.legend(shadow=True, fontsize=30, fancybox=True)#,loc="lower right")

plt.show()

seq