matplotlib(3)
生活随笔
收集整理的這篇文章主要介紹了
matplotlib(3)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
plt.gcf()與plt.gca()
當前的圖表和子圖可以使用plt.gcf()和plt.gca()獲得。可讓邊框變換顏色。
x = np.linspace(-10,10,100) y = np.sin(x) plt.plot(x,y,'r-*') ax = plt.gca() ax.spines["right"].set_color('red')#右邊 ax.spines["left"].set_color('green')#左邊 ax.spines["top"].set_color('yellow')#上 ax.spines["bottom"].set_color('orange')#下若把參數改為set_color(‘none’),則邊框消失
plt.figure("sei",figsize = (5,5),dpi = 100)#設置畫布大小 x = np.linspace(-10,10,100) y = np.sin(x) plt.plot(x,y,'r-*') ax = plt.gca() ax.spines["right"].set_color('none') ax.spines["left"].set_color('g') ax.spines["top"].set_color('none') ax.spines["bottom"].set_color('y') #坐標軸先讓右和上的邊框消失 ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') ax.spines['bottom'].set_position(('data',0)) ax.spines['left'].set_position(('data',0))plt.figure()
figure(num=None,figsize=None,dpi=None,facecolor=None,edgecolor =None,frameon=True)
- num:圖像編號或名稱,數字為編號,字符串為名稱
- figsize:指定figure的寬和高,單位為英寸
- dpi:參數指定繪圖對象的分辨率,即每英寸多少個像素,缺省值為80
- facecolor:背景顏色
- edgecolor:邊框顏色
- frameon:是否顯示邊框
plt.savefig()
可以將畫出的圖保存下來
plt.savefig("F:\\xixi.jpg")#可自定義名字條形圖
a = np.arange(10) data = np.random.randint(1,11,10) data array([ 3, 1, 3, 9, 9, 8, 1, 9, 4, 10]) plt.bar(a,data,facecolor = 'orange',edgecolor = 'red',lw = 3,hatch = '.',width = 0.7,alpha = 0.6) plt.barh(a,data,alpha = 0.6) index = np.arange(5) data1 = np.array([3,4,6,8,9]) data2 = np.array([11,23,6,5,1]) data3 =np.array ([12,6,21,8,26]) plt.bar(index,data1,color = 'yellow',label = 'a') plt.bar(index,data2,bottom = data1,color = 'orange',label = 'b') plt.bar(index,data3,bottom = (data2 + data1),color = 'red',label = 'c') index = np.arange(5) data1 = [3,4,6,8,9] data2 = [11,23,6,5,1] data3 =[12,6,21,8,26] b = 0.3 plt.bar(index,data1,b,color = 'yellow',label = 'a') plt.bar(index+b,data2,b,color = 'orange',label = 'b') plt.bar(index+b*2,data3,b,color = 'red',label = 'c')總結
以上是生活随笔為你收集整理的matplotlib(3)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 系统盘复制到u盘怎么装 U盘如何安装系统
- 下一篇: matplotlib(4)饼图