-
-
Notifications
You must be signed in to change notification settings - Fork 403
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
Datetime64 fixes #816
Datetime64 fixes #816
Changes from all commits
a4f8b56
f0e33d2
a720c2a
eba660c
ae6369b
dba53f6
f801d42
8d4392d
3540868
97763af
4d6714f
09bf924
613e82f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
from __future__ import unicode_literals | ||
|
||
from itertools import product | ||
|
||
import numpy as np | ||
from matplotlib import cm | ||
from matplotlib import pyplot as plt | ||
from matplotlib.collections import LineCollection | ||
from matplotlib.dates import date2num, DateFormatter | ||
|
||
import param | ||
|
||
from ...core import OrderedDict | ||
from ...core import OrderedDict, Dimension | ||
from ...core.util import (match_spec, unique_iterator, safe_unicode, | ||
basestring, max_range, unicode) | ||
from ...element import Points, Raster, Polygons, HeatMap | ||
|
@@ -59,8 +61,19 @@ class CurvePlot(ChartPlot): | |
def get_data(self, element, ranges, style): | ||
xs = element.dimension_values(0) | ||
ys = element.dimension_values(1) | ||
return (xs, ys), style, {} | ||
dims = element.dimensions() | ||
if xs.dtype.kind == 'M': | ||
dt_format = Dimension.type_formatters[np.datetime64] | ||
dims[0] = dims[0](value_format=DateFormatter(dt_format)) | ||
return (xs, ys), style, {'dimensions': dims} | ||
|
||
def init_artists(self, ax, plot_args, plot_kwargs): | ||
xs, ys = plot_args | ||
if xs.dtype.kind == 'M': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth adding a comment mentioning what the 'M' code means. I assume it is the numpy datetime64 type? |
||
artist = ax.plot_date(xs, ys, '-', **plot_kwargs)[0] | ||
else: | ||
artist = ax.plot(xs, ys, **plot_kwargs)[0] | ||
return {'artist': artist} | ||
|
||
def update_handles(self, key, axis, element, ranges, style): | ||
artist = self.handles['artist'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,9 +262,6 @@ class GridPlot(CompositePlot): | |
show_legend = param.Boolean(default=False, doc=""" | ||
Legends add to much clutter in a grid and are disabled by default.""") | ||
|
||
tick_format = param.String(default="%.2f", doc=""" | ||
Formatting string for the GridPlot ticklabels.""") | ||
|
||
xaxis = param.ObjectSelector(default='bottom', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this parameter is now deprecated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, yes, we have a system for tick formatting using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will at least need to be mentioned in the CHANGELOG. Other than that I think it is fine. |
||
objects=['bottom', 'top', None], doc=""" | ||
Whether and where to display the xaxis, supported options are | ||
|
@@ -496,13 +493,15 @@ def _layout_axis(self, layout, axis): | |
yticks = [(plot_height/2)+(r*(plot_height+border_height)) for r in range(self.rows)] | ||
|
||
layout_axis.set_xticks(xticks) | ||
layout_axis.set_xticklabels(self._process_ticklabels(sorted(set(dim1_keys)), dims[0])) | ||
layout_axis.set_xticklabels([dims[0].pprint_value(l) | ||
for l in sorted(set(dim1_keys))]) | ||
for tick in layout_axis.get_xticklabels(): | ||
tick.set_rotation(self.xrotation) | ||
|
||
ydim = dims[1] if layout.ndims > 1 else None | ||
layout_axis.set_yticks(yticks) | ||
layout_axis.set_yticklabels(self._process_ticklabels(sorted(set(dim2_keys)), ydim)) | ||
layout_axis.set_yticklabels([ydim.pprint_value(l) if ydim else '' | ||
for l in sorted(set(dim2_keys))]) | ||
for tick in layout_axis.get_yticklabels(): | ||
tick.set_rotation(self.yrotation) | ||
|
||
|
@@ -529,19 +528,6 @@ def _layout_axis(self, layout, axis): | |
return layout_axis | ||
|
||
|
||
def _process_ticklabels(self, labels, dim): | ||
formatted_labels = [] | ||
for k in labels: | ||
if dim and dim.value_format: | ||
k = dim.value_format(k) | ||
elif not isinstance(k, (str, type(None))): | ||
k = self.tick_format % k | ||
elif k is None: | ||
k = '' | ||
formatted_labels.append(k) | ||
return formatted_labels | ||
|
||
|
||
def _adjust_subplots(self, axis, subaxes): | ||
bbox = axis.get_position() | ||
l, b, w, h = bbox.x0, bbox.y0, bbox.width, bbox.height | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the datetime64 objects will use datetime style formatting? That is fine, assuming datetime64 doesn't have its own formatting conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's nice behavior, datetime64 can't be formatted directly so it converts to regular datetime first and then applies the formatter.