Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inverting a datetime / plot_date y-axis #3522

Closed
Horrifior opened this issue Sep 16, 2014 · 1 comment
Closed

Inverting a datetime / plot_date y-axis #3522

Horrifior opened this issue Sep 16, 2014 · 1 comment

Comments

@Horrifior
Copy link

Dear all,

there have been few mails using the same topic-name on the matplotlib-user mailinglist today, and as suggested by some other users there could be a bug associated with inverting axis using datetime-objects... for brevity, I just attach the short code snippet which should show the problem:

This code is running fine as long as any of the two commands intended to invert the y-axis are commented out.

import matplotlib.pyplot; matplotlib.pyplot.rcdefaults()

import numpy
import matplotlib.pyplot
import datetime

def plot_grid(ax):
    grid_x=numpy.arange(17)+0.5
    grid_y=[]

    for y in range(2013,2019):
        for m in range(1,13,3):
            grid_y+=[matplotlib.dates.date2num(datetime.datetime.strptime("01."+str(m)+"."+str(y)+" 0:00", "%d.%m.%Y %H:%M"))]
    for i in range(len(grid_x)):
        matplotlib.pyplot.plot_date([grid_x[i],grid_x[i]], [grid_y[0],grid_y[-1]],'k', xdate=False, ydate=True)
    for i in range(len(grid_y)):
        matplotlib.pyplot.plot_date([grid_x[0],grid_x[-1]],[grid_y[i],grid_y[i]],'k', xdate=False, ydate=True)


ymin=matplotlib.dates.date2num(datetime.datetime.strptime("01."+str(1)+"."+str(2013)+" 0:00", "%d.%m.%Y %H:%M"))
ymax=matplotlib.dates.date2num(datetime.datetime.strptime("01."+str(12)+"."+str(2018)+" 0:00", "%d.%m.%Y %H:%M"))
fig, ax = matplotlib.pyplot.subplots()
plot_grid(ax)

##matplotlib.pyplot.ylim(ymax,ymin)
##ax.invert_yaxis()
matplotlib.pyplot.savefig('test.png')
matplotlib.pyplot.show()

[TAC edited to introduce formatting]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants