# Plotly can't display negative bars from matlotlib figures

**URL:** <https://community.plotly.com/t/plotly-cant-display-negative-bars-from-matlotlib-figures/12151>\
**Category:** 📊 Plotly Python\
**Created:** [July 27, 2018, 5:41pm UTC](https://community.plotly.com/t/plotly-cant-display-negative-bars-from-matlotlib-figures/12151 "2018-07-27T17:41:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![windflower715](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/windflower715/32/3697_2.png) [@windflower715](https://community.plotly.com/u/windflower715)\
**Post date:** [July 27, 2018, 5:41pm UTC](https://community.plotly.com/t/plotly-cant-display-negative-bars-from-matlotlib-figures/12151/1 "2018-07-27T17:41:59Z")

</div>

I ran into a an issue with tls.mpl\_to\_plotly(matplotlib\_figure) The matplotlib figure has negative value, and it plots fine.

However, when I convert it to using tls.mpl\_to\_plotly, the negative bars will become positive, and I really don’t know how to solve it.

I have tried to set [‘layout’][‘barmode’] =‘relative’, which didn’t help. Could any provide any suggestions on how to fix this?

Your help is greatly appreciated!

---

<div class="post-metadata">

**Author:** ![michaelbabyn](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/michaelbabyn/32/3569_2.png) [@michaelbabyn](https://community.plotly.com/u/michaelbabyn)\
**Post date:** [July 27, 2018, 10:14pm UTC](https://community.plotly.com/t/plotly-cant-display-negative-bars-from-matlotlib-figures/12151/2 "2018-07-27T22:14:00Z")

</div>

try setting `plotly_fig['data'][i]['base'] = 'relative'` where i is the index of each bar trace in your graph.

another problem I had was that `tls.mpl_to_plotly` converted the negative numbers in the y axis to positive ones and I had to change them back manually. See my example code below. Even after setting base mode to relative the chart didn’t work and I needed to reset the y axis.

I’m sorry this is such a work-around.

````auto
import matplotlib.pyplot as plt

import plotly.offline as py
# Learn about API authentication here: https://plot.ly/python/getting-started
# Find your api_key here: https://plot.ly/settings/api

y = [3, 10, -7, 5, 3, 4.5, 6, 8.1]
N = len(y)
x = range(N)
width = 1/1.5
plt.bar(x, y, width, color="blue")

fig = plt.gcf()
plotly_fig = tls.mpl_to_plotly(fig)
py.iplot(plotly_fig)

plotly_fig['data'][0]['base'] ='relative'
py.iplot(plotly_fig)

plotly_fig['data'][0]['y']=y
py.iplot(plotly_fig)```
````
