|
From: John H. <joh...@gm...> - 2008-01-14 20:25:41
|
>
I have some code that produces a series of graphs of data over time.
For the most part it works well, but for certain combinations of
dates the two plots do not line up, due to the width of the bars in
the first subplot. What is the best way for force my second
subplot's x axis to be identical to that of the first subplot?
Thanks!
Here is minimal code reproducing the problem:
import matplotlib
from datetime import *
import time
from pylab import *
def toOrd(strDate):
return datetime(*time.strptime(strDate,"%m/%d/%y")[0:5]).toordinal()
def main():
startDate = toOrd("05/24/05")
endDate = toOrd("11/21/06")
dates = range(startDate,endDate,7)
figure(1)
axis = subplot(211,axisbelow=True)
plot_date(dates,dates,visible = False)
axis.bar(dates,dates, width=3.0)
axis = subplot(212,axisbelow=True)
plot_date(dates,dates) #,'-',color = priceColor)
show()
if __name__ == '__main__':
main()
|
|
From: John H. <joh...@gm...> - 2008-01-16 18:47:34
|
bump. please...?
Begin forwarded message:
>
> I have some code that produces a series of graphs of data over
> time. For the most part it works well, but for certain
> combinations of dates the two plots do not line up, due to the
> width of the bars in the first subplot. What is the best way for
> force my second subplot's x axis to be identical to that of the
> first subplot?
>
> Thanks!
>
> Here is minimal code reproducing the problem:
>
> import matplotlib
> from datetime import *
> import time
> from pylab import *
>
>
> def toOrd(strDate):
> return datetime(*time.strptime(strDate,"%m/%d/%y")[0:5]).toordinal()
>
> def main():
>
> startDate = toOrd("05/24/05")
> endDate = toOrd("11/21/06")
>
> dates = range(startDate,endDate,7)
> figure(1)
>
> axis = subplot(211,axisbelow=True)
> plot_date(dates,dates,visible = False)
> axis.bar(dates,dates, width=3.0)
>
> axis = subplot(212,axisbelow=True)
> plot_date(dates,dates) #,'-',color = priceColor)
>
> show()
>
>
>
> if __name__ == '__main__':
> main()
>
|
|
From: Eric F. <ef...@ha...> - 2008-01-16 20:03:33
|
John Harrison wrote:
> bump. please...?
>
> Begin forwarded message:
>>
>> I have some code that produces a series of graphs of data over time.
>> For the most part it works well, but for certain combinations of dates
>> the two plots do not line up, due to the width of the bars in the
>> first subplot. What is the best way for force my second subplot's x
>> axis to be identical to that of the first subplot?
Check the sharex kwarg. In the examples directory, see ganged_plots.py,
shared_axis_demo.py, and any others that include the sharex kwarg.
Eric
>>
>> Thanks!
>>
>> Here is minimal code reproducing the problem:
>>
>> import matplotlib
>> from datetime import *
>> import time
>> from pylab import *
>>
>>
>> def toOrd(strDate):
>> return datetime(*time.strptime(strDate,"%m/%d/%y")[0:5]).toordinal()
>>
>> def main():
>>
>>
>> startDate = toOrd("05/24/05")
>> endDate = toOrd("11/21/06")
>>
>>
>> dates = range(startDate,endDate,7)
>> figure(1)
>>
>>
>> axis = subplot(211,axisbelow=True)
>> plot_date(dates,dates,visible = False)
>> axis.bar(dates,dates, width=3.0)
>>
>>
>> axis = subplot(212,axisbelow=True)
>> plot_date(dates,dates) #,'-',color = priceColor)
>>
>>
>> show()
>>
>>
>>
>> if __name__ == '__main__':
>> main()
>>
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
|
|
From: John H. <joh...@gm...> - 2008-01-16 20:11:03
|
Thanks Eric! Here is corrected code that works:
import matplotlib
from datetime import *
import time
from pylab import *
def toOrd(strDate):
return datetime(*time.strptime(strDate,"%m/%d/%y")[0:5]).toordinal()
def main():
startDate = toOrd("05/24/05")
endDate = toOrd("11/21/06")
dates = range(startDate,endDate,7)
figure(1)
ax1 = subplot(211,axisbelow=True)
plot_date(dates,dates,visible = False)
ax1.bar(dates,dates, width=3.0)
ax2 = subplot(212,axisbelow=True, sharex=ax1)
plot_date(dates,dates) #,'-',color = priceColor)
show()
if __name__ == '__main__':
main()
On Jan 16, 2008, at 1:02 PM, Eric Firing wrote:
> John Harrison wrote:
>> bump. please...?
>> Begin forwarded message:
>>>
>>> I have some code that produces a series of graphs of data over
>>> time. For the most part it works well, but for certain
>>> combinations of dates the two plots do not line up, due to the
>>> width of the bars in the first subplot. What is the best way for
>>> force my second subplot's x axis to be identical to that of the
>>> first subplot?
>
> Check the sharex kwarg. In the examples directory, see
> ganged_plots.py, shared_axis_demo.py, and any others that include
> the sharex kwarg.
>
> Eric
>
>
>>>
>>> Thanks!
>>>
>>> Here is minimal code reproducing the problem:
>>>
>>> import matplotlib
>>> from datetime import *
>>> import time
>>> from pylab import *
>>>
>>>
>>> def toOrd(strDate):
>>> return datetime(*time.strptime(strDate,"%m/%d/%y")[0:5]).toordinal()
>>>
>>> def main():
>>>
>>>
>>> startDate = toOrd("05/24/05")
>>> endDate = toOrd("11/21/06")
>>>
>>>
>>> dates = range(startDate,endDate,7)
>>> figure(1)
>>>
>>>
>>> axis = subplot(211,axisbelow=True)
>>> plot_date(dates,dates,visible = False)
>>> axis.bar(dates,dates, width=3.0)
>>>
>>>
>>> axis = subplot(212,axisbelow=True)
>>> plot_date(dates,dates) #,'-',color = priceColor)
>>>
>>>
>>> show()
>>>
>>>
>>>
>>> if __name__ == '__main__':
>>> main()
>>>
>> ---------------------------------------------------------------------
>> ---
>> ---------------------------------------------------------------------
>> ----
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2008.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> ---------------------------------------------------------------------
>> ---
>> _______________________________________________
>> Matplotlib-users mailing list
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
|