Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7639513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:26:12+00:00 2026-05-31T08:26:12+00:00

I’m looking at the custom projection example in the matplotlib gallery — I’m trying

  • 0

I’m looking at the custom projection example in the matplotlib gallery — I’m trying to modify it to plot only the southern hemisphere. I have adjusted the necessary [-pi/2,pi/2] limits to [-pi/2,0]. Now I’ve been looking at:

def _gen_axes_patch(self):
    """
    Override this method to define the shape that is used for the
    background of the plot.  It should be a subclass of Patch.

    In this case, it is a Circle (that may be warped by the axes
    transform into an ellipse).  Any data and gridlines will be
    clipped to this shape.
    """
    #return Circle((0.5, 0.5), 0.5)
    return Wedge((0.5,0.5), 0.5, 180, 360)

def _gen_axes_spines(self):
    return {'custom_hammer':mspines.Spine.circular_spine(self,
                                                  (0.5, 0.5), 0.25)}

As you can see, I’ve replaced the Circle patch with a Wedge. This is what the projection plot currently looks like:
projection plot

The spine still follows the circle/ellipse — how can I specify that I want the spine to follow the boundary of the wedge?

I am not sure how best to modify the spine, so any help would be very much appreciated!

Thanks,

Alex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:26:14+00:00Added an answer on May 31, 2026 at 8:26 am

    Just for the record, you’re definitely jumping straight into the deep end of the pool if you’re still new to python. (And kudos to you for going right in!)

    What you’re doing requires a reasonably detailed knowledge of the inner workings of matplotlib, which is a rather complex library.

    That having been said, it’s a good way to learn quickly!

    For something like this, you need to understand the internal architecture of how things are structured instead of just the “public” api.

    For most of this, you have to dig in and “use the source”. For any project, the documentation of the inner workings is the code itself.

    That having been said, for a simple case, it’s pretty straight-forward.

    import numpy as np
    from matplotlib.projections.geo import HammerAxes
    import matplotlib.projections as mprojections
    from matplotlib.axes import Axes
    from matplotlib.patches import Wedge
    import matplotlib.spines as mspines
    
    class LowerHammerAxes(HammerAxes):
        name = 'lower_hammer'
        def cla(self):
            HammerAxes.cla(self)
            Axes.set_xlim(self, -np.pi, np.pi)
            Axes.set_ylim(self, -np.pi / 2.0, 0)
    
        def _gen_axes_patch(self):
            return Wedge((0.5, 0.5), 0.5, 180, 360)
    
        def _gen_axes_spines(self):
            path = Wedge((0, 0), 1.0, 180, 360).get_path()
            spine = mspines.Spine(self, 'circle', path)
            spine.set_patch_circle((0.5, 0.5), 0.5)
            return {'wedge':spine}
    
    mprojections.register_projection(LowerHammerAxes)
    
    if __name__ == '__main__':
        import matplotlib.pyplot as plt
        fig = plt.figure()
        ax = fig.add_subplot(111, projection='lower_hammer')
        ax.grid(True)
        plt.show()
    

    enter image description here

    Let’s dig into the _get_axes_spines method a bit:

    def _gen_axes_spines(self):
        """Return the spines for the axes."""
        # Make the path for the spines
        # We need the path, rather than the patch, thus the "get_path()"
        # The path is expected to be centered at 0,0, with radius of 1
        # It will be transformed by `Spine` when we initialize it
        path = Wedge((0, 0), 1.0, 180, 360).get_path()
    
        # We can fake a "wedge" spine without subclassing `Spine` by initializing 
        # it as a circular spine with the wedge path. 
        spine = mspines.Spine(self, 'circle', path)
    
        # This sets some attributes of the patch object. In this particular 
        # case, what it sets happens to be approriate for our "wedge spine"
        spine.set_patch_circle((0.5, 0.5), 0.5)
    
        # Spines in matplotlib are handled in a dict (normally, you'd have top,
        # left, right, and bottom, instead of just wedge). The name is arbitrary
        return {'wedge':spine}
    

    Now there are a few problems with this:

    1. Things aren’t centered within the axis properly
    2. The axes patch could be scaled a bit larger to properly take up the room within the axes.
    3. We’re drawing the grid lines for the full globe and then clipping them. It would be more efficient to only draw them inside our “lower” wedge.

    However, when we take a look at how HammerAxes is structured, you’ll notice that a lot these things (especially the centering of the axis patch) are effectively hard-coded into the transforms. (As they mention in the comments, it’s meant to be a “toy” example, and making the assumption that you’re always dealing with the full globe makes the math in the transformations much simpler.)

    If you want to fix these, you’ll need to tweak several of the various transforms in HammerAxes._set_lim_and_transforms.

    However, it works reasonably well as-is, so I’ll leave that as an exercise to the reader. 🙂 (Be warned, that part’s a bit harder, as it requires a detailed knowledge of matplotlib’s transformations.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.