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

Adding Scalar as a Baseline Option#27308

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

Open
EricRLeao1311 wants to merge14 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromEricRLeao1311:Better-support-for-stackplot

Conversation

EricRLeao1311
Copy link

PR summary

Allowing an int to be received as a baseline option in stackplots, to prevent cases where the baseline is not sensible enough.
Closes#27129

PR checklist

@ksunden
Copy link
Member

I think that restricting to anint is deeply flawed, really we want any scalar value (including unitful scalars, such as datetime objects). Certainlyat least there is no reason to disallow floating point scalar values if we are allowing setting the baseline to arbitrary values.

I also think that perhaps even more important than the code change allowingbaseline to be scalar is the documentation (and testing) aspects of this code change, which are not reflected here.

@pedrompecanha
Copy link
Contributor

pedrompecanha commentedNov 19, 2023
edited
Loading

I'm pair programming alongside@EricRLeao1311. We've changed to code so it accepts floats, but we still have some questions about testing and documentation. About testing, how could we improve/fix it? We found some tests in test_axes.py, but they use a @image_comparison wrapper, and we are unsure on how to make it work for our case. We tried to include some cases, but we don't know if they were made correctly. And about documentation, we attempted to improve the docstrings related to the function. Is that enough? Thanks!

try:
axs[0, 0].stackplot(range(100), d.T, baseline=5)
except ValueError as e:
print("Error when using an integer as baseline:", e)
Copy link
Member

Choose a reason for hiding this comment

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

If you are testing something that should fail the test if the error is raised, then remove the try/except.

If you are testing that thisshould raise, then usewith pytest.raises(...) which will ensure that the exception is actually raised (where printing will just ignore whether or not an exception was raised)

@ksunden
Copy link
Member

I still think float is too restrictive, and that we should be looking at unit-aware changes, so whilefloat is a lot better than specificallyint, I still don't think it is far enough

@pedrompecanha
Copy link
Contributor

Ok, I see that you want it to be more expansive than float-only, but we are having trouble on what types we should accept and how to treat the different types. Could you enlighten us in any type of way?

@ksunden
Copy link
Member

Because the units system can have arbitrary values, there isno restriction on the type, much like thebottom value for e.g.ax.bar, which is documented as "float or arraylike", but also contains an explicit note about if it has units.

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.bar.html

This should be treated similarly, in that it gets passed throughaxes._process_unit_info:

# It is possible for y (bottom) to contain unit information.

Where this has odd behavior:

  • categorical data (in general), as you cannot just add them in their raw forms and so I don't think it can make sense here (you could maybe add them post-conversion, but I think you actually want to convertmost things after adding...)
  • categorical data (in specific), even if we sorted out the general problems, if you happen to have a category called "zero", "sym", "wiggle", etc, then you would be unable to specify those as the baseline... This is an edge case I don't see astoo big of a problem, but it is odd.

I think that it could be:

  • remove thecheck_in_list entirely
  • add anelse case to theif baseline == chain which callsaxes._process_unit_info(("y", baseline)) setsfirstline = baseline and doesstack += baseline (theremay be some shape massaging for 1D data, like there is forsym, but for scalar data it should just be+=
  • Do something about thenp.promote_types call... not sure exactly what, but e.g. datetime64 should not be promoted (and will error)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ksundenksundenksunden left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
Status: Waiting for author
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[ENH]: Better support for stackplot with units [particularly datetimes]
3 participants
@EricRLeao1311@ksunden@pedrompecanha

[8]ページ先頭

©2009-2025 Movatter.jp