Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Santa Cruz Mountains map (also, annotating is slightly hard) #7

Closed
kratsg opened this issue May 2, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@kratsg
Copy link

commented May 2, 2019

Here's the code that generates a nice map of the Santa Cruz Mountains (and adds a point identifying the Santa Cruz Institute for Particle Physics)

  • a workaround to color the label a different color
  • slight issues with figuring out how to annotate things correctly using actual lat/long coordinates
from ridge_map import RidgeMap
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

bgcolor = np.array([65,74,76])/255.

scipp = (-122.060510, 36.998776)
rm = RidgeMap((-122.087116,36.945365,-121.999226,37.023250))
scipp_coords = ((scipp[0] - rm.longs[0])/(rm.longs[1] - rm.longs[0]),(scipp[1] - rm.lats[0])/(rm.lats[1] - rm.lats[0]))

values = rm.get_elevation_data(num_lines=150)
ridges = rm.plot_map(values=rm.preprocess(values=values, lake_flatness=1, water_ntile=0, vertical_ratio=240),
            label='Santa Cruz\nMountains',
            label_x=0.75,
            label_y=0.025,
            label_size=90,
            kind='elevation',
            background_color=bgcolor,
            line_color = plt.get_cmap('cool'),
            size_scale=50)

[c for c in ridges.get_children() if isinstance(c, matplotlib.text.Text) and 'Santa Cruz' in c._text][0].set_color('white')
ridges.text(scipp_coords[0]+0.005, scipp_coords[1]+0.005, 'SCIPP', size=40, color="white", transform=ridges.transAxes, verticalalignment="bottom", zorder=len(values)+10)
ridges.add_patch(plt.Circle(scipp_coords, 0.0025, color="white", fill=True, transform=ridges.transAxes, zorder=len(values)+10))
ridges.get_figure().savefig('santa_cruz.pdf', bbox_inches='tight')

Screenshot 2019-05-02 10 54 06

@ColCarroll

This comment has been minimized.

Copy link
Owner

commented May 2, 2019

Beautiful! I'll add this to the examples section if that's ok!

I'll look at what I can do for those difficulties. At the very least, adding a RidgeMap.lat_long_to_data method seems useful.

@kratsg

This comment has been minimized.

Copy link
Author

commented May 2, 2019

Beautiful! I'll add this to the examples section if that's ok!

Fine with me!

I'll look at what I can do for those difficulties. At the very least, adding a RidgeMap.lat_long_to_data method seems useful.

Yeah. I mean, there's already a ridges.annotate method, however I couldn't figure out the right combination of coordinates to make things work and annotate as expected, e.g. the following did not work for me

ridges.annotate('SCIPP', scipp)
ridges.annotate('SCIPP', scipp_coords)
ridges.annotate('SCIPP', scipp, transform=ridges.transAxes)
ridges.annotate('SCIPP', scipp_coords, transform=ridges.transAxes)
ridges.annotate('SCIPP', scipp, transform=ridges.transData)
ridges.annotate('SCIPP', scipp_coords, transform=ridges.transData)
ridges.annotate('SCIPP', ridges.transAxes.transform(scipp))
ridges.annotate('SCIPP', ridges.transAxes.transform(scipp_coords))
ridges.annotate('SCIPP', ridges.transAxes.inverted().transform(scipp))
ridges.annotate('SCIPP', ridges.transAxes.inverted().transform(scipp_coords))
ridges.annotate('SCIPP', ridges.transData.transform(scipp))
ridges.annotate('SCIPP', ridges.transData.transform(scipp_coords))
ridges.annotate('SCIPP', ridges.transData.inverted().transform(scipp))
ridges.annotate('SCIPP', ridges.transData.inverted().transform(scipp_coords))

although I admit I'm not very well-versed in MPL transforms, but it seems like the axes used in this package are somewhat not trivial/straightforward to build.

@ColCarroll

This comment has been minimized.

Copy link
Owner

commented May 5, 2019

Closing as we added the beautiful example, but would be happy to merge improved annotating.

@ColCarroll ColCarroll closed this May 5, 2019

@cranmer

This comment has been minimized.

Copy link

commented May 6, 2019

I was doing this for a gift. One issue is that it seems the lat/long position is for zero-altitude. So to get the point right one needs the vertical off-set as well and how that's projected into the frame.

@cranmer

This comment has been minimized.

Copy link

commented May 6, 2019

Also, to match the font:

import matplotlib.font_manager as fm
from ridge_map import FontManager

prop = fm.FontProperties(fname= rm.font.get_file())

and then add fontproperties=prop to the ridges.text call

ridges.text(scipp_coords[0]+0.005, scipp_coords[1]+0.005, 'SCIPP', size=40, color="white", transform=ridges.transAxes, verticalalignment="bottom", zorder=len(values)+10,fontproperties=prop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.