Skip to content

set_xlim doesn't work with time series plots #1339

Closed
@wesm

Description

@wesm

Ideally would like to be able to do:

plt.set_xlim(['1/1/2005', '1/1/2012'])

or even pass datetime.datetime objects. Not sure how feasible this is. I think the trick is setting the converter field on the subplot's X axis according to:

In [22]: ax.xaxis.convert_units??
Type:       instancemethod
Base Class: <type 'instancemethod'>
String Form:<bound method XAxis.convert_units of <matplotlib.axis.XAxis object at 0x3809310>>
Namespace:  Interactive
File:       /home/wesm/code/repos/matplotlib/lib/matplotlib/axis.py
Definition: ax.xaxis.convert_units(self, x)
Source:
    def convert_units(self, x):
        if self.converter is None:
            self.converter = munits.registry.get_converter(x)

        if self.converter is None:
            #print 'convert_units returning identity: units=%s, converter=%s'%(self.units, self.converter)
            return x

        ret =  self.converter.convert(x, self.units, self)
        #print 'convert_units converting: axis=%s, units=%s, converter=%s, in=%s, out=%s'%(self, self.units, self.converter, x, ret)
        return ret

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions