python - Matplotlib: Labels on projection plot grid lines similar to clabel() -


i'm doing bunch of work various spherical projection plots using astropy wcs package, , have run frustrations concerning grid lines. grid lines not intersect image bounding box or multiple intersect @ same place, can go unlabeled or have labels rendered illegible. able insert grid line labels in each line, akin matplotlib.pyplot.clabel() function applied contour plots, in matplotlib example. can't embed image new user; apologies.

i know can place labels using text(), figtext(), or annotate(), since clabel() works figure functionality exists, if hasn't been applied grid lines. projection plotting aside, know way in-line grid line labels akin clabel() can applied grid lines on plain rectangular plot?

to annotate gridlines, may use positions of major ticks (as positions @ gridlines created).

import matplotlib.pyplot plt import numpy np  x = np.linspace(0,10) y = np.sin(x)*10  fig, ax = plt.subplots() ax.plot(x,y) ax.grid()  xi in ax.xaxis.get_majorticklocs():     ax.text(xi,0.8, "{:.2f}".format(xi), clip_on=true, ha="center",             transform=ax.get_xaxis_transform(), rotation=90,             bbox={'facecolor':'w', 'pad':1, "edgecolor":"none"}) yi in ax.yaxis.get_majorticklocs():     ax.text(0.86,yi, "{:.2f}".format(yi), clip_on=true, va="center",             transform=ax.get_yaxis_transform(),              bbox={'facecolor':'w', 'pad':1, "edgecolor":"none"})  plt.show() 

enter image description here


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -