Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

FIX: Warn when trying to set_facecolor on a array-mapped Collection#29715

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
timhoffm wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromtimhoffm:warn-collection-array-facecolor
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletionslib/matplotlib/collections.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -778,6 +778,16 @@ def _get_default_facecolor(self):
return mpl.rcParams['patch.facecolor']

def _set_facecolor(self, c):
if self.get_array() is not None:
# Note: we cannot use self._face_is_mapped here because it is
# lazily calculated in update_scalarmappable(), but the equivalent
# logic there is that colormapping from an array takes precedence
# over an explicit facecolor.
_api.warn_external(
"Setting the facecolor has no effect because there is colormapped "
"array data, which takes precedence. Use `set_array(None)` before "
"setting the facecolor to override this.")

if c is None:
c = self._get_default_facecolor()

Expand Down
8 changes: 8 additions & 0 deletionslib/matplotlib/tests/test_collections.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -333,6 +333,14 @@ def test_add_collection():
assert ax.dataLim.bounds == bounds


def test_collection_facecolor():
pc = plt.figure().subplots().scatter([0, 1, 2], [0, 1, 2], c=[0, 0.5, 1])
with pytest.warns(match="Setting the facecolor has no effect"):
pc.set_facecolor(['r', 'g', 'b'])
# the returned facecolor is the colormapped one:
pc.get_facecolor() == plt.get_cmap()([0, 0.5, 1])


@mpl.style.context('mpl20')
@check_figures_equal(extensions=['png'])
def test_collection_log_datalim(fig_test, fig_ref):
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp