Announcing Dash Bio 1.0.0 πŸŽ‰ : a one-stop-shop for bioinformatics and drug development visualizations.

Histogram bargap=0 not setting to 0

Hello,

I am having issues with using bargap=0 to create a histogram. Here is how it looks without any usage of bargap.


The look with using bargap=0 is the same like without it. However, the graph changes when I use bargap=0.1

So, apparently bargap works, but not when removing the lines between the bars. It is important to mention that the initial graph (first one) contains some bars borders not shown, and some are shown. To those who are shown, their width between each other is not constant, too.

Here is my code.

fig = px.histogram(plot_data, x=plot_data.index, y=plot_data.columns, color_discrete_sequence=colors)
    fig.update_layout(
        title='Active developers over time',
        yaxis_title_text='Number of active developers',
        plot_bgcolor="white",
        bargap=0
    )
    fig.update_traces(nbinsx=50, selector=dict(type='histogram'))
    fig.show()

What is the problem here? Is it a bug or I am missing something in my code?

EDIT:

I also tried using marker_line_width = 0 and bargroupgap=0, but ended up with the same result as the first picture.

This is an odd behavior. What Plotly version are you running? I checked with Plotly v 5.5.0 and bargap works as expected.
The function px.histogram() instantiates the class go.Histogram
https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/plotly/express/_chart_types.py#L426,
and here is a simple example illustrating that bargap=0 removes the gaps:

import plotly.graph_objects as go
import numpy as np
np.random.seed=4321
fig=go.Figure(go.Histogram(x=np.random.normal(0,1,150), histnorm="probability", nbinsx=12))
fig.update_layout(width=600, height=400, bargap=0)
fig.show()

bagap_0

fig.update_layout(width=600, height=400, bargap=0.03)

bagap_03

By the probability theory rules the histograms reveal better the distribution of data sets, when they are plotted with small gaps. A massive, instead of a histogram is not met in probability and statistics books.

Hey, empet.

First of all, thanks for replying. I have tried your code out, and it works as you showed. However, I am still having issues with the charts showing no gaps.

It is a fairly new project, and therefore I am using the latest version v5.5.0. What I have also done is save the sample data that I use to create the charts above, and I will attach it here, so you could try it out. It is as simple as it could get. The link is - https://easyupload.io/3i71nj

If you fear security issues, here is a screenshot of the sample_data. Try to recreate it

@afrenegade

Here is the plot with your code and your data (except the color):

So I don’t know why you get gaps :frowning:
I stress again: your data are samples from discrete distributions (like binomial, geometric distribution, and so on), because each column consists in integer values. Hence there is no reason to illustrate their distribution estimation with a massive, not a real histogram with gaps.

But if you insist on such a presentation, then I can suggest just to reinstall Plotly. During the last days more questions have been addressed here on forum or as an issue on plotly.py repo, concerning unexpected behavior of different traces, and after reinstallation the issue disappeared.

Hey, empet.

Thanks for replicating the chart. So, now my conclusion is perhaps the issue is connected to the environment that I use. In this case, I have a virtual environment - pipenv.