-1

How can I make xticks of a plot in specific frequency? Here is my code:

# read data
df = pd.read_csv("newData/000001.csv")
df1 = df.loc[df['seqNo'] == 48]
df1 = df1.sort_values(by = 'date')
df1['date'] = df1['date'].astype(str)
# show plot
plt.plot(df1['date'], df1['close'], 'yellow', label = 'close')
plt.legend()
plt.xlabel("date")
plt.ylabel("value")
plt.title("000001")
plt.show()

and the plot, the x axis is too dense: image here

and the part of the plot is : enter image description here

The datatype of xaxis is string.

Mike Müller
  • 82,630
  • 20
  • 166
  • 161
Zeongwan
  • 1
  • 2

1 Answers1

1

You can use pandas default plotting:

df = pd.read_csv("newData/000001.csv")
df1 = df.loc[df['seqNo'] == 48]
df1 = df1.sort_values(by = 'date')

p = df.plot('date', 'close',  color='yellow', title="000001")
p.set_ylabel('value')

This does automatic spacing of the x ticks.

Example:

enter image description here

Mike Müller
  • 82,630
  • 20
  • 166
  • 161