Open
Description
While mpl_to_plotly
is little known and receives little love, this bug is pretty easy to fix. Would you be open to a PR?
import matplotlib.pyplot as plt
from plotly.tools import mpl_to_plotly
from plotly.offline import plot
In matplotlib this produces a barplot with labels:
labels = ['a', 'b', 'c']
values = [1, 2, 3]
f = plt.figure(figsize=(6, 4))
plt.bar(labels, values)
plt.tight_layout()
But conversion to plotly looses the labels:
plotly_fig = mpl_to_plotly(f)
plot(plotly_fig)
A minimal fix would be to modify prep_ticks
by appending:
if axis_dict.get("type") == "date":
return axis_dict
vals = []
texts = []
for tick in axis.majorTicks:
vals.append(tick.get_loc())
texts.append(tick.label1.get_text())
if texts:
axis_dict = {}
axis_dict['tickmode'] = 'array'
axis_dict['tickvals'] = vals
axis_dict['ticktext'] = texts
return axis_dict
which produces:
prep_ticks
is defined in:
plotly.py/plotly/matplotlylib/mpltools.py
Lines 428 to 514 in c54a2bd