Python3繪圖庫Matplotlib(01)

1 First plots with Matplotlib

簡單的繪圖1

簡單的繪圖2

簡單的繪圖3

2 網格 = grid

3 設置座標軸的取值範圍 = axis xlim ylim

方法1:總體設置

[xmin,  xmax, ymin, ymax]   ===》plt.axis([xmin, xmax, ymin, ymax])

方法2:分別設置

plt.xlim([xmin, xmax])
plt.ylim([ymin, ymax])

4 設置座標含義標籤 = label

5 設置圖片的總體標題 = title

6 設置圖例 = legend

方法2:

plt.plot(x, x*1.5)
plt.plot(x, x*3.0)
plt.plot(x, x/3.0)
plt.legend(['Normal', 'Fast', 'Slow'])

圖例的位置參數:loc = Code

String Code
best 0
upper right 1
upper left 2
lower left 3
lower right 4
right 5
center left 6
center right 7
lower center 8
upper center 9
center 10

7 一副完整的圖像

8 保存圖片 = savefig

import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.savefig("plot123.png")
plt.savefig('plot123_2.png', dpi=200)
#
import matplotlib as mpl
mpl.rcParams['figure.figsize']
mpl.rcParams['savefig.dpi']
mpl.reParams['Agg']

9 本小結全部代碼示例

import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.show()

import matplotlib.pyplot as plt
x = range(6)
plt.plot(x, [xi**2 for xi in x])
plt.show()


import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0.0, 6.0, 0.01)
plt.plot(x, [x**2 for x in x])
plt.show()

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 5)
plt.plot(x, x*1.5, x, x*3.0, x, x/3.0)
plt.grid(True)
plt.show()

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 5)
plt.plot(x, x*1.5, x, x*3.0, x, x/3.0)
plt.axis() # 顯示當前座標軸的極限取值範圍 x->(0.85, 4.15), y->(-0.25, 12.58)
plt.axis([0, 5, -1, 13]) # 重新設置當前座標軸的範圍 
plt.show()

import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.xlabel('This is the X axis') #這個是x軸的標籤
plt.ylabel('This is the Y axis') #這個是y軸的標籤
plt.show()

import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.title('Simple plot') # 圖像的標題
plt.show()

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 5)
plt.plot(x, x*1.5, label="Normal")
plt.plot(x, x*3.0, label="Fast")
plt.plot(x, x/3.0, label="Slow")
plt.legend() # 設置圖例
plt.show()

import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1, 5)
plt.plot(x, x*1.5, x, x*3.0, x, x/3.0)
plt.grid(True)
plt.title('Sample Growth of a Measure')
plt.xlabel('Samples')
plt.ylabel('Values Measured')
plt.legend(['Normal', 'Fast', 'Slow'], loc = 'upper left')
plt.show()

import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.savefig("plot123.png")
import matplotlib as mpl
mpl.rcParams['figure.figsize']
mpl.rcParams['savefig.dpi']
plt.savefig('plot123_2.png', dpi=200)

 


知識在於點點滴滴的積累,我會在這個路上Go ahead,python

有幸看到我博客的朋友們,若能學到知識,請多多關注以及討論,讓咱們共同進步,揚帆起航。

後記:打油詩一首

適度鍛鍊,量化指標spa

考量天氣,設定目標code

科學鍛鍊,成就體標orm

高效科研,實現學標blog

相關文章
相關標籤/搜索