from PIL import Image
例:
from PIL import Image
import numpy as np
im = np.array(Image.open("C:/Users/sssss/.spyder-py3/123.jpg"))
print(im.shape,im.dtype)
例:
from PIL import Image
import numpy as np
a = np.array(Image.open("C:/Users/sssss/.spyder-py3/123.jpg"))
print(a.shape,a.dtype)
b = [255,255,255] -a
im = Image.fromarray(b.astype('uint8'))
im.save("C:/Users/sssss/.spyder-py3/1234.jpg")
将彩色照片变成灰度图片:
from PIL import Image
import numpy as np
a = np.array(Image.open("C:/Users/sssss/.spyder-py3/123.jpg").convert('L'))
b = 255 - a
im = Image.fromarray(b.astype('uint8'))
im.save("C:/Users/sssss/.spyder-py3/1234.jpg")
import matplotlib.pyplot as plt
例1:
import matplotlib.pyplot as plt
plt.plot([3,1,4,5,2])
plt.ylabel("grade")
plt.savefig('test',dpi=600) #PNG文件
plt.show()
例2:
plt.plot([0,2,4,6,8],[3,1,4,5,2])
plt.ylabel("grade")
plt.axis([-1,10,0,6])
plt.show()
plt.plot(x,y,format_string,**kwargs)
注:当绘制多条曲线时,各条曲线的x不能省略
例:
import matplotlib.pyplot as plt
import numpy as np
a = np.arange(10)
plt.plot(a,a*1.5,'go-',a,a*2.5,'rx',a,a*3.5,'*',a,a*4.5,'b-,')
plt.show()
例1:
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family']='SimHei' #黑体
plt.plot([3,1,4,5,2])
plt.ylabel("纵轴(值)")
plt.savefig('test',dpi=600)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family']='STSong'
matplotlib.rcParams['font.size']=20
a = np.arange(0.0,5.0,0.02)
plt.xlabel('横轴:时间')
plt.ylabel('纵轴:振幅')
plt.plot(a,np.cos(2*np.pi*a),'r--')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
a = np.arange(0.0,5.0,0.02)
plt.xlabel('横轴:时间',fontproperties='SimHei',fontsize=20)
plt.ylabel('纵轴:振幅',fontproperties='SimHei',fontsize=20)
plt.plot(a,np.cos(2*np.pi*a),'r--')
plt.show()
plt.subplot2grid(GrindSpec,CurSpec,colspan=1,rowspan=1)
例:
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
gs = gridspec.GridSpec(3,3)
ax1 = plt.subplot(gs[0,:])
ax2 = plt.subplot(gs[1,:-1])
ax3 = plt.subplot(gs[1:,-1])
ax4 = plt.subplot(gs[2,0])
ax5 = plt.subplot(gs[2,1])