Refactor UltraLegend builder into dedicated module#570
Refactor UltraLegend builder into dedicated module#570cvanelteren wants to merge 14 commits intomainfrom
Conversation
(cherry picked from commit 1ff58be)
|
I saw you are refactoring legend handlings, is there any change you can make some public helper function or construct function like the way legendkit deos? Though legend handling is more convince in ultraplot than matplotlib, sometime manually construct a legend is still needed. For example, I usually use legendkit to generate a legend, but it's not totally compatible with cartopy (or ultraplot, i'm not sure). from legendkit import legend
fig,ax=pplt.subplot(proj='cyl')
g = gpd.read_file(r'some_example_shapefile.shp')
ax.add_geometries(g.geometry, crs=pcrs, label='LabelNameOfSomething')
# ax.legend() #doesn't work
legend(legend_items=[
('rect', 'LabelNameOfSomething', {'fc': 'r', 'alpha':0.7}),
('circle', "OtherPlace', {'fc': 'none', 'ec': 'blue'})
], loc='lower left', title='Legend') |
|
Oh cool! I was not aware of this package. Can you elaborate a bit more on what your snippet does that we cannot right now? |
|
It has a very simple, very useful document, provide several examples, would you mind checkout webpage: https://legendkit.readthedocs.io/en/latest/tutorial/legend.html |
|
Ah this is similar to what I wanted to achieve with #571 |
|
I can see if I can work this into that PR. This one is merely decoupling the logic that within Will give this some thought how to make it more flexible. |
|
Thanks, it will be very useful. |
…iffs (cherry picked from commit 3c34186)
This draft PR extracts the axes legend construction flow into a dedicated
UltraLegendbuilder module to reduce complexity inAxes._add_legend, centralize input normalization/layout/style application, and improve maintainability while preserving existing behavior. It also adds targeted legend tests around panel span inference and placement edge cases to guard the refactor. Follow-up to #529.