# Matplotlib to plotly bar chart label loss

**URL:** <https://community.plotly.com/t/matplotlib-to-plotly-bar-chart-label-loss/13383>\
**Category:** 📊 Plotly Python\
**Created:** [September 7, 2018, 4:40pm UTC](https://community.plotly.com/t/matplotlib-to-plotly-bar-chart-label-loss/13383 "2018-09-07T16:40:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![henry.k.turner](https://avatars.discourse-cdn.com/v4/letter/h/a183cd/32.png) [@henry.k.turner](https://community.plotly.com/u/henry.k.turner)\
**Post date:** [September 7, 2018, 4:40pm UTC](https://community.plotly.com/t/matplotlib-to-plotly-bar-chart-label-loss/13383/1 "2018-09-07T16:40:19Z")

</div>

Hi all,  
I decided I wanted to start using plotly, because I was very impressed by its features. I’ve already done a lot of work in matplotlib so I was hoping I could convert some of the graphs I’ve already made into plotly. However I’ve been running into a problem converting bar charts where if my xaxis consists of strings, then the bar labels get converted into numbers. Is there a way to keep the string labels that i’m missing??  
Thanks in advance to for any help that can ben given!!

An example of this problem Is shown below

y = [3, 10, 7, 5]  
x = [‘hi’, ‘hello’, ‘yo’, ‘gday’]

mpl\_fig = plt.figure(figsize=(40,20))  
ax = mpl\_fig.add\_subplot(111)  
ax.bar(x, y, color = ‘b’, alpha = 0.8)  
plt.xticks(rotation=90, fontsize = 25)  
plt.yticks(fontsize = 25)  
plt.ylabel(‘x test’, fontsize = 32)  
plt.xlabel(‘y test’, fontsize = 32)

plotly\_fig = tls.mpl\_to\_plotly(mpl\_fig)  
plotly.offline.iplot(plotly\_fig)

producing the graph below

 ![plotly_problem](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/7/74c16e23385ca8f58d6f388b36a80c2b75a0de3d.png)

---

<div class="post-metadata">

**Author:** ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)\
**Post date:** [September 8, 2018, 12:27pm UTC](https://community.plotly.com/t/matplotlib-to-plotly-bar-chart-label-loss/13383/2 "2018-09-08T12:27:06Z")

</div>

Hi @henry.k.turner,

Unfortunately the matplotlib conversion can only support a subset of the matplotlib (and plotly) plotting functionality. It does look like categorical axes labels get lost in the conversion at this point. If you’d like, you could create a issue at [https://github.com/plotly/plotly.py/issues](https://github.com/plotly/plotly.py/issues). The matplotlib conversion support hasn’t gotten a lot of attention lately, but it would still be helpful to have this shortcoming logged.

I would be interested to understand your usecase a little more. Do you have matplotlib figures saved as files that you would like to convert? Or do you have a lot of existing scripts/notebooks with matplotlib plotting code that you’d like to append a conversion command to the end? Are you interested in converting the matplotlib plotting code to plotly.py plotting code eventually?

I’m wondering if a more helpful workflow might be for us to take a matplotlib figure and produce the plotly.py code that creates as much of the figure as possible. This way even if the resulting figure isn’t perfect, you’d hopefully have a good starting point for the conversion.

What do you think?  
-Jon

---

<div class="post-metadata">

**Author:** ![henry.k.turner](https://avatars.discourse-cdn.com/v4/letter/h/a183cd/32.png) [@henry.k.turner](https://community.plotly.com/u/henry.k.turner)\
**Post date:** [September 10, 2018, 9:09am UTC](https://community.plotly.com/t/matplotlib-to-plotly-bar-chart-label-loss/13383/3 "2018-09-10T09:09:31Z")

</div>

hi @jmmease

Thanks for you reply. I was interested in taking matplotlib plotting code and appending the conversion command to the end. I would be interested in converting the matplotlib code to plotly.py code eventually. I can add a couple of examples of my matplotlib plotting code (though with anonymised variable names and labels) if this helps?

Thanks,

Harry
