国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python matplotlib畫曲線例題解析

2020-02-15 21:19:58
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了Python matplotlib畫曲線例題解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

初學者,練習以下片段:

代碼1:用 一元一次函數 畫直線

import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-2, 2, 50)print(x)y = 2*x + 1plt.plot(x, y)ax = plt.gca()ax.spines['bottom'].set_position(('data',0))ax.spines['left'].set_position(('data',0))plt.show()

代碼2:用 一元二次函數 畫拋物線

import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-4, 6, 50)print(type(x))print(x)y = x**2 - x*2+1plt.plot(x, y)plt.show()

代碼3:用反比例函數 畫曲線

import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-11, 11, 110)print(x)y =10/xplt.plot(x, y)ax = plt.gca()ax.spines['bottom'].set_position(('data',0))ax.spines['left'].set_position(('data',0))plt.show()

代碼4:子坐標系的應用

import matplotlib.pyplot as pltfig = 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:子坐標系的應用

import matplotlib.pyplot as pltfig = 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:用已知少量坐標值畫曲線

import matplotlib.pyplot as pltplt.plot([1, 2, 3, 4], [10, 20, 25, 30], color='lightblue', linewidth=3)plt.xlim(0.5, 4.5)plt.show()

代碼7:畫離散點

mport matplotlib.pyplot as pltimport numpy as npx = np.arange(10)y = np.random.randn(10)print(y)plt.scatter(x, y, color='red', marker='+')plt.show()

代碼8:畫出正弦曲線

import numpy as npimport matplotlib.pyplot as pltx=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()            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 崇左市| 甘谷县| 霍州市| 太保市| 东兴市| 赞皇县| 昭通市| 万源市| 郓城县| 类乌齐县| 潮安县| 大渡口区| 右玉县| 增城市| 金塔县| 临漳县| 长宁区| 庆安县| 周宁县| 上思县| 长丰县| 绍兴市| 平陆县| 门头沟区| 蓝田县| 永济市| 招远市| 深水埗区| 安化县| 迭部县| 姜堰市| 丹寨县| 承德县| 海兴县| 西宁市| 德安县| 万荣县| 长泰县| 且末县| 蓝山县| 正宁县|