Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Colorbar grid postion #18340

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

Closed

Conversation

shawnchenx6
Copy link
Contributor

PR Summary

I made a little change so that now the anchor argument in make_axes_gridspec mimic the behavior of that in make_axes. Now the postion of colorbar is determined by anchor and shrink, should be very useful when shrink < 1.0

The effect is demostrated in the plot below. Now I can place the colorbar at different place with different shrinked size.

import numpy as np
import matplotlib as mpl
import matplotlib,pyplot as plt

x = np.random.randn(100)
y = np.random.randn(100)
fig = plt.figure()
ax = fig.add_subplot()
mappable = ax.scatter(x,y, c=y)
ax.figure.colorbar(mappable, ax=ax, anchor=(0,0.3), shrink=0.5) 

A good figure

Before the change, we can achieve that using ax.figure.colorbar(mappable, ax=ax, anchor=(0,0.3), use_gridspec=False) , however, this will create a colorbar as a Axes not a Subplot, when I use subplots_ajust to adjust the border margins, I got the following plot.

fig = plt.figure()
ax = fig.add_subplot()
mappable = ax.scatter(x,y, c=y)
ax.figure.colorbar(mappable, ax=ax, anchor=(0,0.3), shrink=0.5, use_gridspec=False) 
ax.figure.subplots_adjust(bottom=0.1)

A bad figure

It seems the colorbar Axes is ignored and my plot is re-placed according to its panchor parameter that make_axes set. It bothers me when I have multiple plots and wanna adjust the plots border margins and wspace, hspace.

gridspec offers a better approach and is the default setting when creating a colorbar, however, I want the colorbar to be 0.5 size and placed at the bottom right, which is mot implemented.

So this is what I did basically.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak
Copy link
Member

jklymak commented Aug 24, 2020

Follow these instructions for the rebase: https://matplotlib.org/3.1.3/devel/gitwash/development_workflow.html#rebasing-on-trunk (please note the instructions to create a backup branch, just in case ;-))

@tacaswell tacaswell added this to the v3.4.0 milestone Aug 28, 2020
@tacaswell
Copy link
Member

This seems like a reasonable feature to add to me 👍

In addition to being rebased, this should get a whats_new entry and maybe an example in the gallery?

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as needs changes, as this needs a rebase and a what's new entry. @ShawnChen1996 let us know if you need help with anything!

@shawnchenx6
Copy link
Contributor Author

I had some issues as I switched to a new laptop, but finally managed to set up the environment and rebase this.

The head of this branch I rebase on is very different than the previous one. I made the modification accordingly and so far the graph looks good, may need a big tuning on the pad between colorbar and the plot. Will work on this soon and rewriting the test function. Will also work on WHAT'S NEW and EXAMPLE.

May I ask is this rebasing correct? As there are 9 check failures.

@jklymak
Copy link
Member

jklymak commented Sep 24, 2020

I don't think you pushed your rebase to GitHub. But.... Before you do, make sure you've backed up this version of the branch, just in case there are errors....

Thanks for persevering with this!

@shawnchenx6 shawnchenx6 deleted the colorbarGridPostion branch September 25, 2020 15:47
@shawnchenx6 shawnchenx6 restored the colorbarGridPostion branch September 25, 2020 16:14
@shawnchenx6 shawnchenx6 deleted the colorbarGridPostion branch September 25, 2020 16:19
@shawnchenx6
Copy link
Contributor Author

sorry for the trouble I made. I opened the another pull request with rebased code. This PR is closed. The new PR is #18575

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.