底图 drawparallels 刻度标签颜色
Basemap drawparallels tick label color
我可能有一个简单的问题。我的代码的简化版本如下:
# 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 等...
有什么想法吗?谢谢!
经过大量搜索,我终于在网上找到了解决方案。不是直接的,但它有效:
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()
我可能有一个简单的问题。我的代码的简化版本如下:
# 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 等...
有什么想法吗?谢谢!
经过大量搜索,我终于在网上找到了解决方案。不是直接的,但它有效:
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()