Only show values that exist in the x axis data?

I wasn’t able to find a solution from previous posts, can I have the x axis only show values that exist in the x data?


data = {'x': [0, 1, 4, 5, 7, 9], 

        'y': [1, 2, 3, 4, 5, 6]}

sample = pd.DataFrame(data)

test_fig =, x='x', y='y')


I want to only display the x-axis values that exist, eliminating the gaps in the chart.

My actual data is filtered down from having 8000+ entries to only ~200. The x-axis on my barplot varies but can have values anywhere from 1-2281, with all y values being 0<y<1. I need to only chart the x values that are present in the filtered data.

I have tried converting the x series data from int64 to string and other data types but this fails to change anything.

Bump. From my previous research one potential solution I encountered was to go through the data and fill the gaps in x values with a corresponding NaN in y value. Will this actually work?