请问下面这种图是怎么画出来的?用的是什么软件?想知道怎么让坐标轴不等间隔。
问题描述:
答
matlab 三种函数
loglog: x轴y轴均为对数刻度
semilogx:x轴为对数刻度
semilogy:y轴为对数刻度
答
①MATLAB画图实例代码:
%幂函数
x = linspace(-4,4,200);
f1 = 10.^x;
f2 = exp(x);
f3 = 2.^x;
plot(x, f1, 'r', x, f2, 'b', x, f3, 'g', 'LineWidth', 2);
axis([-4, 4, -0.5, 8])
text('Interpreter','latex','String','$10^x$', 'Position', [1, 7.5],'fontsize', 16)
text('Interpreter','latex','String','$e^x$', 'Position', [2.2, 7.5],'fontsize', 16)
text('Interpreter','latex','String','$2^x$', 'Position', [3.2, 7.5],'fontsize', 16)
②python的matplotlib库画图实例代码:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-4, 4, 200)
f1 = np.power(10, x)
f2 = np.power(np.e, x)
f3 = np.power(2, x)
plt.plot(x, f1, 'r', x, f2, 'b', x, f3, 'g', linewidth = 2)
plt.axis([-4, 4, -0.5, 8])
plt.text(1, 7.5, r'$10^x$', fontsize = 16)
plt.text(2.2, 7.5, r'$e^x$', fontsize = 16)
plt.text(3.2, 7.5, r'$2^x$', fontsize = 16)
plt.show()
显然,Python画图更加自然丝滑。