import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl mpl.use('TkAgg') # 定义三个二维数组 xy1 = np.array([[40,0.0364],[50,0.0351],[60,0.0361],[70,0.0356],[80,0.0361]]) xy2 = np.array([[70,0.0356],[80,0.0361],[90,0.0356],[100,0.0358],[110,0.0359]]) xy3 = np.array([[100,0.0358],[110,0.0359],[120,0.0366],[130,0.0351]]) # 画出三条曲线,添加标签 plt.plot(xy1[:,0], xy1[:,1], '-o', markersize=8, linewidth=2, label='curve 1') plt.plot(xy2[:,0], xy2[:,1], '-o', markersize=8, linewidth=2, label='curve 2') plt.plot(xy3[:,0], xy3[:,1], '-o', markersize=8, linewidth=2, label='curve 3') # 添加标签和图例 plt.xlabel('x') plt.ylabel('y') plt.legend() plt.show(),如何把画出来的图长宽比变成2;1
时间: 2023-07-02 22:12:24 浏览: 219
import numpy as np(2).py
你可以使用`plt.figure(figsize=(width, height))`来设置画布的大小,即长宽比。其中`width`和`height`分别代表画布的宽度和高度,可以根据需求进行调整。在这个例子中,我们可以将宽度设置为10,高度设置为5,即可得到长宽比为2:1的图形。具体代码如下:
```
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.use('TkAgg')
# 定义三个二维数组
xy1 = np.array([[40,0.0364],[50,0.0351],[60,0.0361],[70,0.0356],[80,0.0361]])
xy2 = np.array([[70,0.0356],[80,0.0361],[90,0.0356],[100,0.0358],[110,0.0359]])
xy3 = np.array([[100,0.0358],[110,0.0359],[120,0.0366],[130,0.0351]])
# 设置画布大小
plt.figure(figsize=(10, 5))
# 画出三条曲线,添加标签
plt.plot(xy1[:,0], xy1[:,1], '-o', markersize=8, linewidth=2, label='curve 1')
plt.plot(xy2[:,0], xy2[:,1], '-o', markersize=8, linewidth=2, label='curve 2')
plt.plot(xy3[:,0], xy3[:,1], '-o', markersize=8, linewidth=2, label='curve 3')
# 添加标签和图例
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.show()
```
运行上述代码,即可得到长宽比为2:1的图形。
阅读全文