import matplotlib.pyplot as plt转为MATLAB语言
时间: 2023-05-27 07:07:06 浏览: 131
把matplotlib的绘图语句转换为MATLAB语言的方法是:
1. 将import matplotlib.pyplot as plt语句改为import matplotlib.pyplot as mpl。
2. 将plt.plot(x, y)语句改为plot(x, y)。
3. 将plt.xlabel("x")语句改为xlabel('x')。
4. 将plt.ylabel("y")语句改为ylabel('y')。
5. 将plt.title("title")语句改为title('title')。
6. 将plt.legend()语句改为legend()。
7. 将plt.show()语句改为show()。
8. 将plt.savefig("filename.png")语句改为saveas(gcf,'filename.png')。
下面是一个例子:
matplotlib代码:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("y")
plt.title("title")
plt.legend()
plt.show()
plt.savefig("filename.png")
MATLAB代码:
import matplotlib.pyplot as mpl
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
plot(x, y)
xlabel('x')
ylabel('y')
title('title')
legend()
show()
saveas(gcf,'filename.png')
阅读全文
相关推荐


















