Set x axis spacing (ticks) for a Pandas DataFrame chart

I am trying to set the ticks (time steps) of the x axis on my matplotlib Pandas DataFrame graph. My goal is to use the first DataFrame column to use as ticks, but so far I have not been successful.

My attempts so far have included:

Attempt 1:

#See 'xticks'
data_df[header_names[1]].plot(ax=ax, title="Roehrig Shock Data", style="-o", legend=True, xticks=data_df[header_names[0]])

Attempt 2:

ax.xaxis.set_ticks(data_df[header_names[0]])

header_names - this is just a list of column header names, and the dataframe looks like this:

    Compression Velocity   Compression Force  
1               0.000213            6.810879             
2               0.025055          140.693200            
3               0.050146          158.401500            
4               0.075816          171.050200             
5               0.101011          178.639500              
6               0.126681          186.228800              
7               0.150925          191.288300            
8               0.176597          198.877500        
9               0.202269          203.937000        
10              0.227466          208.996500         
11              0.252663          214.056000    

And here is the data in CSV format:

Compression Velocity,Compression Force
0.0002126891606,6.810879
0.025055073079999997,140.6932
0.050145696,158.4015
0.07581600279999999,171.0502
0.1010109232,178.6395
0.12668120459999999,186.2288
0.1509253776,191.2883
0.1765969798,198.8775
0.2022691662,203.937
0.2274659662,208.9965
0.2526627408,214.056

And here is the implementation of reading and plotting:

data_df = pd.read_csv(file).astype(float)
fig = Figure()
ax = fig.add_subplot(111)
ax.set_xlabel("Velocity (m/sec)")
ax.set_ylabel("Force (N)")
data_df[header_names[1]].plot(ax=ax, title="Roehrig Shock Data", style="-o", legend=True)

The current chart is as follows:

Currently, the X axis represents the number of rows in the data frame (for example, 12), not the actual values ​​in the first column.

Is there a way to use the data from the first column in the data frame to set the x-axis as ticks / intervals / time steps?

+4
1

:

data_df.plot(x='Compression Velocity', y='Compression Force', xticks=d['Compression Velocity'])

enter image description here

+8

All Articles