所以我修改了我的代码如下:
plt.figure(figsize=(20,10))
plt.scatter(df.field_size, df.field_lai_mean)
plt.title("Field Size and LAI Plot")
plt.xlabel("Field Size")
plt.ylabel("Mean LAI")
plt.xticks(np.arange(0.00000,0.00013,step=0.000008))
plt.yticks(np.arange(0,8.5,step=0.5))
plt.show()
刚刚定义了xticks和yticks函数,顺利完成!:)
要更改绘图点的颜色,可以使用color属性(见下文)。
在创建子图时,可以通过传递xlim和ylim参数来设置两个轴的限制。
还要注意,我在这里传递了rot参数,以设置x标签的旋转。
要配置x和y间隔,您可以使用例如MultipleLocator,用于major和minor刻度线。还有其他定位器,请搜索Web获取详细信息。
您还可以设置网格(就像我所做的那样)。
因此,您可以将代码更改为:
import matplotlib.pyplot as plt
import matplotlib.ticker as tck
fig = plt.figure(figsize=(10,5))
ax = plt.subplot(xlim=(-0.000003, 0.000123), ylim=(-0.5, 9))
df.plot.scatter(x='field_size', y='field_lai_mean', rot=30, color='r', ax=ax)
plt.title("Field Size and LAI Plot")
plt.xlabel("Field Size")
plt.ylabel("Mean LAI")
ax = plt.gca()
ax.yaxis.set_major_locator(tck.MultipleLocator(2))
ax.yaxis.set_minor_locator(tck.MultipleLocator(0.4))
ax.xaxis.set_major_locator(tck.MultipleLocator(0.00001))
ax.xaxis.set_minor_locator(tck.MultipleLocator(0.0000025))
ax.grid()
plt.show()