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

Allow colorbar.ax.set_ylim to set the colorbar limits? #13948

Copy link
Copy link
Closed
@ImportanceOfBeingErnest

Description

Bug report

Bug summary

Coming from this stackoverflow question I was wondering if it would be useful to allow the limits of the colorbar axes to be used for restricting the range of colors to be shown in the colorbar. I.e.

colorbar.ax.set_ylim(-2, 8) 

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors

x = np.linspace(-2,8)

mima = np.max((np.abs(x.min()), np.abs(x.max())))
norm = mcolors.Normalize(-mima, +mima)

sc = plt.scatter(x,x, c=x, cmap = 'seismic', norm=norm)

cb = plt.colorbar(sc, orientation="horizontal")
cb.ax.set_xlim(x.min(), x.max())

plt.margins(x=0)
plt.savefig("test.png", bbox_inches="tight")
plt.show()

Actual outcome

test

Expected outcome

test

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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