I would like to ask about answers to this question: How do you change the size of figures drawn with matplotlib? This is an 8 year old, highly frequented question with over half a million views. It is also the top result when googling matplotlib change figure size, which is a very common task working with matplotlib.
Apart from the top voted answer, there is another very good solution, stating that the figure size can be set using rcParams
. To do so this answer imports pylab
. This was fine at the time the question was asked and answered. However, by now, the use of pylab
is being deprecated for different reasons.
The matplotlib usage guide says about that:
pylab
is a convenience module that bulk importsmatplotlib.pyplot
(for plotting) andnumpy
(for mathematics and working with arrays) in a single name space. Although many examples usepylab
, it is no longer recommended.
It would therefore be appropriate to change the answer, which currently looks like this
to instead use matplotlib.pyplot
like this
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = 5, 10
The question is: Is this appropriate?
I'm not a big fan of editing answers. However, the reason I would like to change this answer is that it seems to be often used by a lot of people (also by people later asking new questions on SO) and it would be good if they didn't use a depreciated code.
The reason I'm asking here is that there is another answer from half a year ago on this thread, which does exactly this
Editing the original answer would then somehow make this new answer meaningless. For which one might argue that it already is, since technically, using rcParams
is a known solution for 8 years already.
We could of course also wait till the new answer gets 200 upvotes and stays above the old one, but until then it might not be obvious to everyone that they should not be using pylab
.
Can someone give an experienced suggestion on how to handle this (and if the answer is to edit the old answer, what to do about the new one)?
(This is no duplicate of this question because my question directly addresses a very specific case where the answer itself is acutally correct and only some header code is leading to a desirable edit.
Update: I now made the proposed edit on the answer and left a comment below it, explaining it. The reason is that this edit does not change the solution, nor the meaning, nor the author's intention and is thereby clearly encouraged by the help center, where, as @Braiam points out in his answer, it says
Editing is important for keeping questions and answers clear, relevant, and up-to-date. Common reasons for edits include: [...] To correct minor mistakes or add updates as the post ages"
Update2: The answer in question has now been locked at a state which does not reflect any of the discussed options. It now looks like this:
The last edit before it was locked has been made by @Félix Gagnon-Grenier and while he and others here argue that no edit to the code should be made, the edit yet has a different code than the original post. So if people think that no edit whatsoever should be made to the code, one would need to rollback the answer to the 2011 version where the code was from pylab import *
instead of from pylab import rcParams
. There was good reason to change this back then, and the edit I am proposing here is actually in the same direction, changing the import to be better suited for people's needs and avoiding unnecessary imports if used in larger projects.
I would at this point ask people to think over their argument of "not changing code" and give an explanation of why the 2014 edit of the question is acceptable and the edit discussed here is not in their view.
Second, the answer as it is now is certainly the worst of all possible solutions, because it starts with a big yellow deprecation warning (btw. yellow is not meant to be used for such things). This will for sure lead people not to use this solution, which is not at all what we want. We want to let them use the solution, but the solution should be imported from pylab
and not from pyplot
.
A lot of people who are active in this thread have never actually worked with python and its module structure, so it seems necessary to remind them that the actual python object rcParams
is the same in both cases.
As said, the answer as it currently is, needs to change. I could imagine to roll back to 2011 and add a note about using the newer answer instead, which to me just adds a lot of unnecessary noise to the question, but would be consitent with the "no code editing" strategy. Or, we could just do the proposed edit with a note that this edit has been performed.