You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a datetime vector for color mapping a plot, the colorbar treats it as a numerical vector where units are nanoseconds. You can see this in this discussion. It is possible however, to change the scale so that it shows human readable dates, but it's quite cumbersome and I had to try many times before finding a working solution here.
I think that the colorbar, in these cases, should have a readable scale by default, and matplotlib already uses it when one of the axes of a plot is datetime, so I think it should be natural to adopt it also for colorbars. Let me know if you agree
In general matplotlib does not do automatic conversion on the data that is run through a norm so expect to jump through some hoops to get a colorbar with dates on it.
On the other hand, if I use the dates for some axis, they get printed just as dates:
plt.scatter(X[:, 0], dates)
plt.show()
Well actually that scale could be improved, this is another problem, but fact is I think there is an inconsistency here between how dates are treated to make scales in axes, and to make scales on colorbars. Dates are not readable anymore when turned into numbers, and a scale is useless if not readable.
The following is basically what is done for the x and y axis if the numpy array is a date. Adding the same support to the third dimension is really hard - in general, colormaps and colorbars are also used for images, pcolors, and contours, and the idea of those having convertible units is non-trivial.
Here, you just convert the dates to floats and then set the proper formatters and locators:
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
jklymak commentedon May 18, 2020
Can you reproduce a self contained example here?
In general matplotlib does not do automatic conversion on the data that is run through a norm so expect to jump through some hoops to get a colorbar with dates on it.
c-foschi commentedon May 19, 2020
sure, here it is:
On the other hand, if I use the dates for some axis, they get printed just as dates:
Well actually that scale could be improved, this is another problem, but fact is I think there is an inconsistency here between how dates are treated to make scales in axes, and to make scales on colorbars. Dates are not readable anymore when turned into numbers, and a scale is useless if not readable.
jklymak commentedon May 19, 2020
The following is basically what is done for the x and y axis if the numpy array is a date. Adding the same support to the third dimension is really hard - in general, colormaps and colorbars are also used for images, pcolors, and contours, and the idea of those having convertible units is non-trivial.
Here, you just convert the dates to floats and then set the proper formatters and locators:
story645 commentedon May 19, 2020
Yes/No - I think you might be able to get it by putting a convertor on NoNorm.
jklymak commentedon May 19, 2020
Its not the conversion thats particularly the issue, its getting the unit info down to the colorbar.
github-actions commentedon Aug 2, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!