vscode里面自動(dòng)的jupyter,有毒,用不了。。。要執(zhí)行下面的操作
pip install pip-autoremove
pip-autoremove.exe jupyter -y
pip install jupyter
新版的code,可以設(shè)置更多的選項(xiàng)
終于看到了我們久違的python,可以使用tab跳出了
shift+Enter
Markdown也正常使用
import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np
import math
def xin():
t = np.linspace(0, math.pi*2, 1000)
# 參數(shù)方程的范圍
x = np.cos(3*t)
y = np.sin(2*t)
# 參數(shù)式
plt.plot(x, y, color='blue',
linewidth=2, label='圓')
# 傳入x,y,顏色是藍(lán)色,線寬,
plt.xlabel('t')
plt.ylabel('h')
# y,x軸的名字
plt.ylim(-1, 1)
plt.xlim(-1.5,1.5)
# 坐標(biāo)軸的長(zhǎng)度
plt.legend()
plt.show()
xin()
先完整的繪制一個(gè)圖
取x點(diǎn)
書寫表達(dá)式
繪制
美化
x = np.cos(50*t)
y = np.sin(39*t)
將參數(shù)改變,再繪制一次
接下來(lái)繪制圓的參數(shù)方程
#半徑
r = 2.0
# 圓心
a, b = (0., 0.)
#參數(shù)方程
theta = np.arange(0, 2*np.pi, 0.01)
x = a + r * np.cos(theta)
y = b + r * np.sin(theta)
很完美
from math import pi
from numpy import cos, sin
from matplotlib import pyplot as plt
if __name__ == '__main__':
'''plot data margin'''
angles_circle = [i * pi / 180 for i in range(0, 360)] # i先轉(zhuǎn)換成double
x = cos(angles_circle)
y = sin(angles_circle)
plt.plot(x, y, 'r')
plt.axis('equal')
plt.axis('scaled')
plt.show()
另外一種繪制圓形的方法~
import numpy as np
from matplotlib import pyplot as plt
r=2.0
a,b=0.0,0.0
# 標(biāo)準(zhǔn)方程
x = np.arange(a-r, a+r, 0.01)
y = b + np.sqrt(r**2 - (x - a)**2)
fig = plt.figure()
axes = fig.add_subplot(111)
axes.plot(x, y) # 上半部
axes.plot(x, -y) # 下半部
axes.axis('equal')
plt.show()
這里是使用的圓的標(biāo)準(zhǔn)方程進(jìn)行繪制
import matplotlib.pyplot as plt
import numpy as np
# create 1000 equally spaced points between -10 and 10
x = np.linspace(-10, 10, 1000)
# calculate the y value for each element of the x vector
y = x**2 + 2*x + 2
fig, ax = plt.subplots()
ax.plot(x, y)
拋物線
import matplotlib.pyplot as plt
a=[]
b=[]
# y=0
# x=-50
for x in range(-50,50,1):
y=x**2+2*x+2
a.append(x)
b.append(y)
#x= x+1
fig= plt.figure()
axes=fig.add_subplot(111)
axes.plot(a,b)
plt.show()
三個(gè)參數(shù),分別代表子圖的行數(shù),列數(shù),圖索引號(hào)
因?yàn)轭l繁的出現(xiàn)add_asubplot()
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplot.html
import matplotlib.pyplot as plt
import numpy as np
'''
Set the values in the variable x
The function arange helps to generate an array with the
following parameters arange(start,end,increment)
'''
x = np.arange(-100,100,1)
'''
Now set the formula in the variable y
'''
y = x**2
'''
Then add the pair (x,y) to the plot
'''
plt.plot(x,y)
'''
Finally show the graph
'''
plt.show()
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 100)
plt.subplot(221)
plt.plot(x, x)
plt.subplot(222)
plt.plot(x, -x)
plt.subplot(223)
plt.plot(x, x ** 2)
plt.subplot(224)
plt.plot(x, np.log(x))
plt.show()
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 100)
# 首先就是生成點(diǎn)列,x
fig = plt.figure()
# 創(chuàng)建一個(gè)大的畫布
ax1 = fig.add_subplot(221)
ax1.plot(x, x)
# 第一個(gè)圖,直接221的位置
ax2 = fig.add_subplot(222)
ax2.plot(x, -x)
# 222的位置,-的斜率
ax3 = fig.add_subplot(223)
ax3.plot(x, x ** 2)
# 二次函數(shù)
ax4 = fig.add_subplot(224)
ax4.plot(x, np.log(x))
# 對(duì)數(shù)形式
plt.show()
pyplot的方式中plt.subplot()參數(shù)和面向?qū)ο笾械腶dd_subplot()參數(shù)和含義都相同
這里針對(duì),子圖的繪制函數(shù)做了一個(gè)簡(jiǎn)單的繪制~
聯(lián)系客服