Lewis Penden
Lewis Penden

Reputation: 3

How can I format tickers for hh:mm in Python matplotlib over a fixed period

I am fairl amateur to programming, but I'm trying to create a python widget that can display the selected photoperiod for a controlled environment growhouse, based on the current time. A GUI would contain this widget so I can know the programmed light hours remotely.

I'm in the early stages of making this and have hit a wall trying to set the time format for the axis.

As you can see in the image, I want to plot the current time against a set time line, with set tickers/intervals.

Any suggestions on improvement are welcome, it's very early days for my Python journey so simple and constructive help or guides appreciated please :)

This is the concept:

(https://i.sstatic.net/x0Z4vsiI.png)

This is my current code:

import matplotlib.pyplot as plt
import matplotlib.dates as md
import datetime
import numpy as np
import matplotlib.ticker as plticker




#Creating an object for the current date and time
timenowfull = datetime.datetime.now()


#converting current time to hh:mm
timenowMMHH = (timenowfull.strftime("%H:%M"))

#testing the current time converted readout
print(timenowMMHH)


dataY = np.array([0.5])
dataX = np.array([timenowMMHH])


plt.ylim(0, 1) 
plt.locator_params(axis='y', nbins=1) 



#creates the scatter plot with a line as a marker
plt.scatter(dataX,dataY,marker="|",s=100000)

And this is the current output:

(https://i.sstatic.net/2fNDiVEM.png)

Upvotes: 0

Views: 41

Answers (0)

Related Questions