Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotating Basemap Meridian labels on x-axis

Is it possible to rotate the meridian labels so that they are no longer overlapping? See the image for an example below. I don't want to reduce the number of meridian lines.

I've tried:

ax = plt.gca()
ax.set_xticklabels( meridians, rotation=45 )

This doesn't do anything in Basemap though.

enter image description here

like image 730
0_o Avatar asked Nov 18 '25 18:11

0_o


1 Answers

The meridian labels aren't xaxis labels. You can still manipulate their text objects:

from mpl_toolkits.basemap import Basemap, cm
import numpy as np
import matplotlib.pyplot as plt

# create figure and axes instances
fig = plt.figure(figsize=(8,8))
ax = fig.add_axes([0.1,0.1,0.8,0.8])
# create polar stereographic Basemap instance.
m = Basemap(projection='stere',lon_0=0,lat_0=30.,lat_ts=45.,\
            width=10000000, height=4000000,
            rsphere=6371200.,resolution='l',area_thresh=10000)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
# draw parallels.
parallels = np.arange(0.,90,5.)
m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
# draw meridians
merid_values = np.arange(0.,360.,10.)
meridians = m.drawmeridians(merid_values,labels=[0,0,0,1],fontsize=10)
for m in meridians:
    try:
        meridians[m][1][0].set_rotation(45)
    except:
        pass
plt.show()

enter image description here

like image 53
cphlewis Avatar answered Nov 20 '25 07:11

cphlewis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!