Skip to content

Colorbar params from docs yield errors #181

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
ToryDeng opened this issue Apr 25, 2025 · 5 comments
Closed

Colorbar params from docs yield errors #181

ToryDeng opened this issue Apr 25, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@ToryDeng
Copy link

From the example you provided, I know I can modify the rotation and alignment of the colorbar's label and remove the spines of the colorbar's axes by manually creating a colorbar. However, I still want to know if there is a more convenient way to modify these properties in UltraPlot.

An example is:

import ultraplot as uplt

cmap = uplt.Colormap("plasma_r")
fig, axs = uplt.subplots(nrows=1, ncols=2, wspace=10)
axs[0].colorbar(cmap, loc="bottom", label="My Label", labelloc="left", length=0.5)

cax = axs[1].colorbar(cmap, loc="bottom", length=0.5)
cax.ax.set_ylabel("My Label", rotation=0, ha="right", va="center")
for spine in cax.ax.spines.values():
    spine.set_visible(False)

Image

The title of the second color bar is easier to read and will not overlap with the xticklabels.

@cvanelteren
Copy link
Contributor

The docs would suggest that you could do

cmap = uplt.Colormap("plasma_r")
fig, axs = uplt.subplots(nrows=1, ncols=2)
cbar = fig.colorbar(
    cmap,
    loc="bottom",
    label="My Label",
    labelloc="right",
    frameon=False,
)
cbar.set_label("My Label", rotation=45)
uplt.show(block=1)

But I see that that produces an error. In the codebase I can see that it indeed does not handle the frame on -- even though it is listed (see https://ultraplot.readthedocs.io/en/latest/api/ultraplot.figure.Figure.html#ultraplot.figure.Figure.colorbar). I have another commit where you can toggle the spines with one command but it is currently private (and not merged yet) I could make it public to handle this and then incorporate it within the colorbar.

All the issues raised are valid and should be incorporated. I do have, however, another 6 ish PRs that need merging and reviewing. In short, this will go on the todos and should not be a big deal to implement.

@cvanelteren
Copy link
Contributor

cvanelteren commented Apr 25, 2025

Btw the code you are looking for is (for now)

import ultraplot as uplt

cmap = uplt.Colormap("plasma_r")
fig, axs = uplt.subplots(nrows=1, ncols=2)
cbar = fig.colorbar(
    cmap,
    loc="bottom",
    label="My Label",
    labelloc="left",
)
cbar.set_label("My Label", rotation=0, ha = "left")
cbar.outline.set_visible(False)
uplt.show(block=1)

@cvanelteren cvanelteren changed the title Is there a more convenient way to modify more properties of the colorbar? Colorbar params from docs yield errors Apr 25, 2025
@cvanelteren cvanelteren added the bug Something isn't working label Apr 25, 2025
@cvanelteren
Copy link
Contributor

cvanelteren commented Apr 26, 2025

@ToryDeng in case you or somebody else wants to tackle this. This may be quicker for development as you seem to be very good at finding bugs 😉. What needs to be done is that the docstring for colorbar would need to match the internal processing.

This would require going through both to see which ones are missing and add those appropriately. I have been meaning to refactor colorbar but that can be done in a separate PR.

Appropriate tests would need to be added to validate the settings, finalized with an image comp.

@cvanelteren
Copy link
Contributor

I actually was less work than I initially thought. Wasn't thinking clearly yesterday. The input parameters work. The docs state that framealpha is only there fore inset colorbars. I added a PR that allows setting the outline. Please see #189.

@cvanelteren
Copy link
Contributor

Fixed in main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants