【Python】Matplotlib图片设置与调整
2021-04-09 本文已影响0人
吵吵人
这里的数据data为Series格式,每一行是一个列表

import matplotlib.pyplot as plt
import geopandas as gpd
N_TYPE = 8
if __name__ == '__main__':
df = gpd.read_file(r'E:\result\c\pre\dcy_12.shp')
for i in range(N_TYPE):
if isinstance(df.iloc[i].loc["dcy_" + str(i)], str):
df["dcy_" + str(i)] = df["dcy_" + str(i)].apply(lambda x: eval(x))
gp = df['dcy_' + str(2)].groupby(df['myID'])
data = gp.get_group(2)
# 生成一个画布
plt.figure()
# 往画布上放置数据
for i in range(len(data)):
if i < 5:
plt.plot(data.iloc[i], label=str(i)) # label设置每一根曲线对应的图例
else:
plt.plot(data.iloc[i])
# 设置坐标轴标题
plt.xlabel("Distance(Cell)", fontsize=12)
plt.ylabel("vNI", fontsize=12)
# 设置坐标轴刻度及标签,xlim是设置画布范围
plt.xticks([0, 1, 2, 3, 4, 5, 6, 7], labels=[1, 2, 3, 4, 5, 6, 7, 8])
# 设置图例位置
plt.legend(loc='upper right')
# 设置图片标题
plt.title('Test Figure')
# 保存至文件
plt.savefig(r'E:\hhh\test_figure.png')
绘图结果:
