Search code examples
plotlyplotly-python

Split plot by range


I have a plot that is spread heavily on the x-axis and Plotly gives me in the default setting only a few barely visible thin lines. So my question is:

  • Is there a way to split only show a selected area in the plot which can, for instance chosen by a dropdown? (Either logarithmic or just ranges 0-1000,1000-20000,>20000)
  • Can the Plot be split in sub-plots (vertical arrangement?)
  • ??? Are there other options I missed?

enter image description here

I have tried already getting them more visible by using log instead of a linear axis but apparently this does not work (Setting width of bars (linear and log))

Edit: This here is the raw data (from the Pandas Dataset):

     Records  Iteration        Type  File Size
639    25000         13  Compressed   26671856
633    25000         10  Compressed   26434058
619    25000          3  Compressed   23342981
620    25000          4    Original   25459652
621    25000          4  Compressed   24485461
..       ...        ...         ...        ...
412       10         14    Original       7211
411       10         13  Compressed       5411
410       10         13    Original       7211
409       10         12  Compressed       5264
389       10          2  Compressed       5388

However what is actually used in this Use-Case is mainly the grouped view:

Records
10           212349
50          6047089
100        13464177
123        10184362
125        10357818
250        20799432
500        41547840
750        75840787
1000      130690551
2500      270894964
5000      830707983
10000    3045818996
12500    1159898272
15000    3139884222
25000     871287571

Solution

  • this can be easily done using facet_col

    data=[[10 , 212349],
    [50, 6047089],
    [100, 13464177],
    [123, 10184362],
    [125, 10357818],
    [250, 20799432],
    [500, 41547840],
    [750, 75840787],
    [1000 , 130690551],
    [2500 , 270894964],
    [5000 , 830707983],
    [10000, 3045818996],
    [12500, 1159898272],
    [15000, 3139884222],
    [25000,  871287571]]
    
    df = pd.DataFrame(data, columns=["record", "count"])
    

    considering the above data

    
    fig = px.bar(df, x='record', y='count', facet_col='record')
    
    # the following line force the subplot to have different x ranges
    fig.update_xaxes(matches=None)
    
    # the following line delete the title of the subplots since they represent same thing as x label
    fig.for_each_annotation(lambda a: a.update(text=""))
    fig.show()
    

    the output is enter image description here