Python matplotlib畫曲線例題解析
這篇文章主要介紹了Python matplotlib畫曲線例題解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
初學(xué)者,練習(xí)以下片段:
代碼1:用 一元一次函數(shù) 畫直線
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-2, 2, 50) print(x) y = 2*x + 1 plt.plot(x, y) ax = plt.gca() ax.spines['bottom'].set_position(('data',0)) ax.spines['left'].set_position(('data',0)) plt.show()
代碼2:用 一元二次函數(shù) 畫拋物線
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-4, 6, 50) print(type(x)) print(x) y = x**2 - x*2+1 plt.plot(x, y) plt.show()
代碼3:用反比例函數(shù) 畫曲線
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-11, 11, 110) print(x) y =10/x plt.plot(x, y) ax = plt.gca() ax.spines['bottom'].set_position(('data',0)) ax.spines['left'].set_position(('data',0)) plt.show()
代碼4:子坐標(biāo)系的應(yīng)用
import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(221) ax2 = fig.add_subplot(222) ax3 = fig.add_subplot(224) ax1.set(xlim=[0.5, 4.5], ylim=[-2, 8], title='Axes Show', ylabel='Y', xlabel='X') plt.show()
代碼5:子坐標(biāo)系的應(yīng)用
import matplotlib.pyplot as plt fig = plt.figure() fig,axes=plt.subplots(nrows=2, ncols=2) axes[0,0].set(xlim=[0.5, 4.5], ylim=[-2, 8], title='Axes Show', ylabel='Y', xlabel='X') axes[0,1].set(title='Upper Right') axes[1,0].set(title='Lower Left') axes[1,1].set(title='Lower Right')
代碼6:用已知少量坐標(biāo)值畫曲線
import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [10, 20, 25, 30], color='lightblue', linewidth=3) plt.xlim(0.5, 4.5) plt.show()
代碼7:畫離散點(diǎn)
mport matplotlib.pyplot as plt import numpy as np x = np.arange(10) y = np.random.randn(10) print(y) plt.scatter(x, y, color='red', marker='+') plt.show()
代碼8:畫出正弦曲線
import numpy as np import matplotlib.pyplot as plt x=np.arange(-2*np.pi,2*np.pi,0.01) y=np.sin(x) plt.plot(x,y) ax = plt.gca() ax.spines['bottom'].set_position(('data',0)) ax.spines['left'].set_position(('data',0)) plt.xticks([-np.pi*2,-np.pi*3/2,-np.pi, -np.pi/2, 0, np.pi/2, np.pi,np.pi*3/2,np.pi*2],[r'$-2\pi$',r'$-\frac{3}{2} \pi$',r'$-\pi$',r'$-\frac{1}{2}\pi$', r'0', r'$\frac{1}{2}\pi$','$\pi$',r'$\frac{3}{2}\pi$',r'$2 \pi$']) plt.show()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 利用python中的matplotlib打印混淆矩陣實(shí)例
- Matplotlib繪制混淆矩陣的實(shí)現(xiàn)
- Python使用matplotlib繪制正弦和余弦曲線的方法示例
- Python matplotlib繪制圖形實(shí)例(包括點(diǎn),曲線,注釋和箭頭)
- matplotlib 曲線圖 和 折線圖 plt.plot()實(shí)例
- Python matplotlib 繪制雙Y軸曲線圖的示例代碼
- 使用matplotlib動(dòng)態(tài)刷新指定曲線實(shí)例
- Python使用matplotlib繪制三維參數(shù)曲線操作示例
- Python使用matplotlib繪制Logistic曲線操作示例
- matplotlib畫混淆矩陣與正確率曲線的實(shí)例代碼
相關(guān)文章
Python爬蟲實(shí)例——scrapy框架爬取拉勾網(wǎng)招聘信息
這篇文章主要介紹了Python爬蟲實(shí)例——scrapy框架爬取拉勾網(wǎng)招聘信息的相關(guān)資料,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07Python爬蟲Xpath定位數(shù)據(jù)的兩種方法
這篇文章主要介紹了Python爬蟲Xpath定位數(shù)據(jù)的方法,第一種方法直接右鍵,將文章路徑復(fù)制下來點(diǎn)擊Copy?full?Xpath,方法二使用@制定標(biāo)簽屬性,搜索指定位置,每種方法給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07TensorFlow車牌識(shí)別完整版代碼(含車牌數(shù)據(jù)集)
這篇文章主要介紹了TensorFlow車牌識(shí)別完整版代碼(含車牌數(shù)據(jù)集),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08Python3實(shí)現(xiàn)的Mysql數(shù)據(jù)庫操作封裝類
這篇文章主要介紹了Python3實(shí)現(xiàn)的Mysql數(shù)據(jù)庫操作封裝類,涉及Python針對mysql數(shù)據(jù)庫的連接、查詢、更新及關(guān)閉連接等相關(guān)操作技巧,需要的朋友可以參考下2018-06-06python tkinter實(shí)現(xiàn)簡單計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了python tkinter實(shí)現(xiàn)簡單計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01python常用的各種排序算法原理與實(shí)現(xiàn)方法小結(jié)
這篇文章主要介紹了python常用的各種排序算法原理與實(shí)現(xiàn)方法,結(jié)合實(shí)例形式總結(jié)分析了冒泡排序、插入排序、選擇排序、快速排序等排序算法的相關(guān)原理與實(shí)現(xiàn)方法,需要的朋友可以參考下2023-04-04Python獲取Windows或Linux主機(jī)名稱通用函數(shù)分享
這篇文章主要介紹了Python獲取Windows或Linux主機(jī)名稱通用函數(shù)分享,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-11-11Python編程求質(zhì)數(shù)實(shí)例代碼
這篇文章主要介紹了Python編程求質(zhì)數(shù)實(shí)例代碼,對求200,1000和100000以內(nèi)的質(zhì)數(shù)進(jìn)行了測試,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01