Peter Melchior wrote:
> Hello,
> 
> I understand that hold() creates a axes if there is none.
> What I want to do is plotting a couple of plots in each of the subplots.
> 
> The data I want to display is stored in a set of files, thus I have a
> loop of plot calls in each subplot:
> 
> hold(True)
> subplot(311)
> for i in range(8):
>     bins = somefunction(i)
>     data = someotherfunction(i)
>     plot(bins,data)
> subplot(312)
> for i in range(8):
> ...
> 
> That's why I want to ensure that hold is set to True.
> Is there a better way of achieving that?

One way is this:

ax = subplot(311)
ax.hold(True)

Or this:
subplot(311)
hold(True)

The plot command will not change the hold state unless you tell it to by 
giving it a hold kwarg, in which case it will only temporarily change 
it--the change will not affect the next plot command.

Another way is to set the default via the rcParams array, as in many of 
the example scripts that come with the source distribution, or via the 
matplotlibrc file.  In both cases, it is the axes.hold parameter.  The 
default is True, so unless you have a non-default matplotlibrc file, you 
should be getting the behavior you want without having to do anything at 
all.  Still, setting it explicitly in your script is a good idea because 
it makes it clear what is going on, and it makes the script immune to 
changes in the matplotlibrc file.

Eric

> 
> Best regards,
> 
> Peter Melchior
> 
> 
> 
> Eric Firing wrote:
>> The pylab hold command sets the hold variable for the current axes. 
>> If there is none, it makes one, hence the full-size axes on which your
>> subplots are superimposed.  The hold variable determines whether
>> subsequent calls to something like "plot" erase the axes first, or
>> superimpose their drawing on whatever was already there.
>>
>> What is it you are really trying to do?
>>
>> Eric
>>
>> Peter Melchior wrote:
>>> Hello everybody,
>>>
>>> when using this very simple script, I get three subplots which lie on
>>> top of a
>>> empty plot covering the whole area of the figure:
>>>
>>> from numpy import *
>>> from pylab import *
>>>
>>> hold(True)
>>> subplot(311)
>>> subplot(312)
>>> subplot(313)
>>> show()
>>>
>>> The result of this code can be viewed here:
>>> https://www.ita.uni-heidelberg.de/~pmelchior/subplot_overlay.png
>>>
>>> If I leave out the line "hold(True)", which could also read
>>> "hold(False)", the
>>> underlying plot disappears.
>>>
>>> Is there a way to avoid that? Or: Is there a preferred position for
>>> the "hold"
>>> command?
>>>
>>> Best regards,
>>>
>>> Peter Melchior 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to