4

My question MatplotlibDeprecationWarning when saving figure even though arguments are not passed has been closed as lacking details, but it seems pretty clear to me. Maybe that's because I'm thinking it, and can't see how it's unclear so I'll try to summarize it below:

  1. I am using matplotlib to draw some graphs and save them
  2. While saving the graphs I am getting warnings from matplotlib about arguments I haven't passed to the save function
  3. My question is how to make the warnings stop (and implicitly why are the warnings showing up)

Could you let me know how my question is unclear and/or does not properly convey the above summary?

Initially I got a comment that it was lacking a MRE, which was true because the code could not be run as is, and I amended that by adding the second code block while the question was still open.

9
  • 5
    Why didn't the last comment on your question help? Commented Oct 18 at 9:20
  • 6
    Seems like a normal sequence of events. Got closed with request for more information, you added more information, now it should be in the reopen queue for review again and it already got a reopen vote. Just need to be patient.
    – Gimby
    Commented Oct 18 at 10:00
  • 4
    @Gimby: From what I can see, the post was closed after the last edit. Either it is still something missing, or the last close vote was wrong.
    – BDL
    Commented Oct 18 at 11:41
  • @BDL Oh man, I saw the red "completed" and thought that was the closure. But no there is a separate event further up the chain. Indeed the edit happened in between the close votes being cast. That's sucky, it really derails normal processing.
    – Gimby
    Commented Oct 18 at 11:55
  • 1
    it got reopened so thanks I guess. I added the implicit part of the question as well because I kinda want to know why this happens
    – KGS
    Commented Oct 18 at 14:36
  • 2
    As is now the question looks good (albeit the MRE is more verbose than it would need to be, a lot of stuff could be removed from the example that shouldn't contribute to the deprecation warning). However, I've tried to reproduce and failed to get the deprecation warnings. That's problematic. Commented Oct 18 at 17:24
  • 4
    Btw. lacking debugging details also includes "shortest code necessary to produce the problem". The close reason title is unfortunately a bit of a misnomer there. By providing unnecessary long code, one lacks the shortest code example to produce the problem, but that really reads awkwardly. Commented Oct 18 at 19:38
  • 2
    Don't forget that it takes 3 votes to close a question, and each of those votes might be for a different reason. I think you only get to see the last one. Commented Oct 18 at 20:16
  • 5
    @MarkRansom I think it's the mode of all the votes (ie the one that appears the most) or some fallback if each of them were different... but I forget what that is
    – S.S. Anne
    Commented Oct 18 at 22:08

1 Answer 1

11

Before considering how to fix the question: it's expected to do some research first. When I put "savefig() got unexpected keyword argument" into a search engine - with the quotes - I got a single result, which was this bug report:

https://github.com/matplotlib/matplotlib/issues/19714

It seems to describe the exact problem you're talking about. It's light on details, but my guess is that the configuration of the Figure that you do causes it to remember state information about values for dpi etc. that are mistakenly reported as having been passed as keyword arguments. Knowing this may help with minimizing the MRE, but chances are good that you still don't really have a suitable Q&A for Stack Overflow, but instead a more detailed bug report for Matplotlib. (Worth checking what happens on newer Matplotlib versions, too.)

On the other hand, if your intended question is simply "how do I suppress warnings from Matplotlib, given that I don't actually care about the issue and consider them benign?", then you really could just ask that without any code - although it's a duplicate, as was stated in the comments.


Your newly provided code does not constitute a MRE.

  • I can't actually even install Matplotlib 3.4.3 straightforwardly in a new venv. This out-of-date Matplotlib was apparently not prepared for backwards-incompatible changes in Numpy 2.x (i.e. it didn't upper-cap Numpy in its dependencies); Pip gets the latest Numpy (2.1.2) and Matplotlib breaks trying to use the removed np.Inf (should be np.inf).

  • After downgrading Numpy to 1.26.4 (the last pre-2 version), I can run the code without an exception - but I don't see any output. Which makes sense in that the code creates an in-memory PNG, then returns it to nowhere. But I don't see the warnings, either (and I did try to mess with Python's -W flag etc. to make sure they weren't being suppressed somewhere else). So as far as I can make out, this is not reproducible.

  • But even if I could reproduce the problem, this is not minimal. It is your responsibility to figure out what parts of the code are necessary to cause the problem, and show us only what is needed.

    • For example, do you get the error if you just try the same savefig call on a newly created Figure, without actually adding anything to it?
    • What if you use the plt.subplots call shown in order to initialize fig, ax, but then don't do anything else before return fig?
    • If that doesn't reproduce the problem in your environment, what things need to be added to the process, out of the code shown, to cause it? Are the line axes relevant? The setting of tight layout? The title?
    • Even if your graph creation needs to be this complex to cause the problem, and you can't figure out any non-essential steps - try to simplify the surrounding code architecture, that clearly doesn't relate to the problem. Do you need to create a class? Do you need to make the dummy graph_map just to look up the same dispatch method each time (as opposed to just... calling it)? Do you need a if __name__ == "__main__" block? Can you hard-code the data into the graph creation process? Can you simplify the data?

To have a suitable question for Stack Overflow, you need to make sure (ideally, by trying it yourself first in a fresh venv):

  1. Can someone else copy and paste the code from the question, in an environment set up with the specified dependencies (if you only specify the Matplotlib version, then you're responsible for checking that blindly installing Matplotlib will work; if other specific versions are needed, determine and state them too), run it, and see the problem?

  2. Will someone else see the exact problem, directly when running the code (i.e. without having to interact any more than necessary or wait for irrelevant long calculations)?

  3. Does this code focus on the problem by doing only the things that are needed to reproduce it?

8
  • 1
    Maybe to come back on "lacking", the question then seems to lack more supporting information on one hand, but also rigor and stringency (leaving out the unnecessary stuff) on the the other hand. Commented Oct 19 at 22:08
  • 5
    @chivracq venv is virtual environment. Commented Oct 20 at 0:19
  • Regarding lack of information of the environment: Pip seems to be not so great at solving - I used micromamba with conda-forge and got a properly solved environment straightaway (I also failed to be able to reproduce the problem, see my comment on OPs question: "I've tried to reproduce with the exact matplotlib version and Python 3.10.15 and cannot get the deprecation warning to show. Installed with: micromamba create -n so1 python matplotlib=3.4.3, then run with micromamba run -n so1 python file.py." Commented Oct 20 at 13:18
  • @CorneliusRoemer from the PyPI page I see that matplotlib 3.4.3 has wheels up to 3.9, but both of us were trying on 3.10. I downloaded the sdist and it doesn't have a pyproject.toml, and its setup.py appears to specify numpy>=1.16. I guess conda-forge is able to offer a "properly solved environment" by just having the solution stored already in a Conda recipe. Did you happen to check the NumPy version in the environment it gave you? Commented Oct 20 at 20:07
  • 1
    @chivracq I fixed the typo. Commented Oct 20 at 20:08
  • Numly 1.26 out of the box. Commented Oct 20 at 23:35
  • 1
    "it's expected to do some research first" Note, however, that lack of research is a down vote reason, not a close vote reason. I know you didn't state explicitly that that contributed to the question's closure, but it's worth pointing out that fact so that readers don't incorrectly infer it.
    – TylerH
    Commented Oct 21 at 13:26
  • @TylerH My finding is that lack of research tends to cause other problems which are close reasons. Commented Oct 21 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .