我可能有一个简单的问题。我的代码的简化版本如下:
# get rid of white stripe on map
ionst, lons=addcyclic(ionst, lons)
#Setting figure attributes
fig=plt.figure(figsize=(15,15),frameon=False, facecolor='gray')
#map settings
m=Basemap(llcrnrlon=-180, llcrnrlat=-87.5, urcrnrlon=180, urcrnrlat=87.5,rsphere=6467997, resolution='l', projection='cyl',area_thresh=10000, lat_0=0, lon_0=0)
#Creating 2d array of latitude and longitude
lon, lat=np.meshgrid(lons, lats)
xi, yi=m(lon, lat)
#plotting data onto basemap
cs=m.imshow(varcor, interpolation=None, alpha=.8, cmap='seismic', vmin=-.02, vmax=.02)
vert=plt.axvline(x=-75, color='black', linewidth=5)
#drawing grid lines
m.drawparallels(np.arange(-90.,90.,30.),labels=[1,0,0,0],fontsize=20)
m.drawmeridians(np.arange(-180.,181.,45.), labels=[0,0,0,1],fontsize=20)
#drawing coast lines
m.drawcoastlines()
当我调用drawparallels和drawmeridians参数时,标签是根据我指定的数组设置的。我想出了如何改变刻度标签的大小,但我不能为我的生活找出如何改变颜色。我尝试直接喂食参数color =,我试过tick_params,我试过xticks,yticks等...
有什么想法吗?谢谢!
答案 0 :(得分:2)
经过广泛搜索,我终于在网上找到了解决方案。不是直截了当但它有效:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
def setcolor(x, color):
for m in x:
for t in x[m][1]:
t.set_color(color)
m = Basemap(lon_0=0)
m.drawcoastlines()
par = m.drawparallels(np.arange(-90,90,30),labels=[1,0,0,1])
setcolor(par,'r')
merid = m.drawmeridians(np.arange(0,360,60),labels=[1,0,0,1])
setcolor(merid,'r')
plt.show()