【发布时间】:2020-12-17 20:18:25
【问题描述】:
我试图在 matplotlib 中使用 pyplot 绘制具有 12 条不同线条的绘图,但是似乎只有 10 种不同的颜色导致其中两种颜色重复。我尝试使用 plt.set_cmap('Set3') 来获得更多可用颜色,但没有任何改变。我该怎么办?我对编程还很陌生,所以我可能会遗漏一些我还没有学到的东西。
这是我正在使用的代码
import netCDF4 as nd
import matplotlib.pyplot as plt
data = []
for k in range(1,13):
nc_file = f'./MIMOC/MIMOC_ML_v2.2_CT_SA_MLP_month{k:02d}.nc'
with nc.Dataset(nc_file) as nc_fid:
lat = nc_fid['LATITUDE'][:]
lon = nc_fid['LONGITUDE'][:]
temp = nc_fid['CONSERVATIVE_TEMPERATURE_MIXED_LAYER'][:,:]
data.append(temp)
months = ['January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
for i in data:
plt.plot(lat, i[:,660], label = months)
plt.legend(months, loc = 'right', bbox_to_anchor=(1.53,0.83), ncol=2)
plt.xlabel('latitude')
plt.ylabel('temperature [degC]')
plt.title('Monthly surface temperature along 30W')
plt.show()
【问题讨论】:
-
我主要想知道的是如何更改此图的颜色图以包含更多颜色 plt.plot(lat, i[:,660], label = months)
标签: python matplotlib plot jupyter-notebook