Major Tick label hourly

My program reads an excel sheet and uses the temperature in the specific excel cell.
My problem is my code is showing all ticks when I only want the Major ticks label.
This code makes the tick labels too close and unreadable
I am very new to this and seek guidance


plt.figure(figsize=(64, 6))
workbook = load_workbook(filename=pathTo)
workbook.sheetnames
[‘Sheet 1’]
sheet = workbook.active
column=sheet[‘C’]
lastCell=(len(column))
last=(len(column))
firstCell=len(column)-7
first=(firstCell)
dataList =
for t in range(8):
print(sheet.cell(row=firstCell, column=3).value)
dataList.append(sheet.cell(row=firstCell, column=3).value)
firstCell=firstCell+1
plt.plot(dataList)
plt.title(‘Temperature over last 8 hours’)
plt.xlabel(‘8 Readings’)
plt.ylabel(‘Temperature’)
plt.gca().xaxis.set_major_locator(mdates.HourLocator())
plt.xticks(rotation=90)
plt.show()

Your dates are strings. Convert to datetime.

Could you please show me how to do so ?

I cannot specifically because I have no idea what is in your spreadsheet. However this problem comes up approximate every day on stack overflow, so there are lots of solution posted there that you can use to base your solution off.

Its a column of temperatures taken hourly in the excel sheet.
Thanks anyway

···

On Sat, 27 Feb 2021 at 17:37, Jody Klymak via Matplotlib <nobody@discourse.matplotlib.org> wrote:

jklymak
February 27

I cannot specifically because I have no idea what is in your spreadsheet. However this problem comes up approximate every day on stack overflow, so there are lots of solution posted there that you can use to base your solution off.


Visit Topic or reply to this email to respond.

To unsubscribe from these emails, click here.

Well, if the data is hourly, and you specify an hourly tick, you are going to get as many ticks as you have data points.

To make a proper datetime axis for this do something like:

time = np.datetime64('2021-01-01', 'h') + np.arange(0,len(dataList))
ax.plot(time, dataList)

and don’t set the locator at first…