python代码:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0.05, 10, 1000)
y = np.cos(x)
plt.plot(x, y, ls="-", lw=2, label="plot figure")
plt.legend()
plt.show()
MATLAB代码:
clear,clc;
x=linspace(0.05,10,1000);
y=cos(x);
plot(x,y)
legend('cos(x)')
MATLAB代码
clc
clear
e=[0 0.05 0.1 0.15 0.25 0.375 0.5 1]
x=0:0.01:5
for i=1:length(e)
y=1./sqrt((1-x.^2).^2+(2*e(i)*x).^2)
plot(x,y)
end
grid on
hold on
axis([0,5,0,3])
python代码
import numpy as np
from matplotlib import pyplot as plt
e=[0,0.05,0.1,0.15,0.375,0.5,1];
x= np.arange(0,5,0.01)
for i in e:
y=1/np.sqrt((1-x**2)**2+(2*i*x)**2);
plt.plot(x,y)
plt.grid();
plt.xlim((0, 5));
plt.ylim((0, 3));
plt.show();
python代码
import matplotlib.pyplot as plt
import numpy as np
data={'a':np.arange(50),
'c':np.random.randint(0,50,50),
'd':np.random.randn(50)}
data['b']=data['a']+10*np.random.randn(50)
data['d']=np.abs(data['d'])*100
plt.scatter('a','b',c='c',s='d',data=data)
plt.xlabel('x')
plt.ylabel('y')
plt.show()
python代码:
from matplotlib import pyplot as plt
import numpy as np
plt.rcParams["font.sans-serif"] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
x=['口罩{}'.format(i) for i in range(1,11)]
y=[np.random.randint(5,100) for _ in range(10) ]
plt.bar(x,y)
plt.xlabel('口罩品牌')
plt.ylabel('价格')
plt.title('口罩')
plt.show()
plt.grid()
from matplotlib import pyplot as plt
import numpy as np
plt.rcParams["font.sans-serif"] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
x=['口罩{}'.format(i) for i in range(1,11)]
y=[np.random.randint(5,100) for _ in range(10) ]
plt.barh(x,y)
plt.ylabel('口罩品牌')
plt.xlabel('价格')
plt.title('口罩')
plt.show()
plt.grid()