Skip to content

_bar does not support date values on the x-axis #91

@seanjh

Description

@seanjh

prettyplotlib seems to choke when the values provided on the x-axis do not support the + operator (or the "width" value does not support the / operator). My code is excerpted below. ppl.bar throws a TypeError, but ppl.plot works wonderfully.

dates = sorted(review_by_date.keys())
review_counts = [review_by_date[k] for k in x]
ma = moving_average(review_counts, 10)

fig, axes = plt.subplots(1, figsize=(16, 10))
ppl.bar(axes, dates, review_counts, annotate=False, linewidth=0)
axes.bar(dates, review_counts, color='green', linewidth=0)  # TypeError
# axes.plot(dates, ma, 'r')
ppl.plot(axes, dates, ma)  # Works
fig.autofmt_xdate()
axes.set_title('Reviews by Date')
axes.set_xlabel('Dates')
axes.set_ylabel('Reviews')
axes.fmt_xdata = mdates.DateFormatter('%Y-%m-%d')

...

prettyplotlib/_bar.pyc in bar(*args, **kwargs)
     48     xtickabels = kwargs.pop('xticklabels', None)
     49     # left+0.4 is the center of the bar
---> 50     xticks = np.array(left) + middle
     51 
     52     # Whether or not to annotate each bar with the height value
TypeError: unsupported operand type(s) for +: 'datetime.date' and 'float'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions