Matplotlib.dates.epoch2num() in Python Last Updated : 19 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.dates.epoch2num() The matplotlib.dates.epoch2num() function is used to convert an epoch or a sequence of epochs to a new date format from the day since 0001. Syntax: matplotlib.dates.epoch2num(e) Parameters: e: It can be an epoch or a sequence of epochs. Returns: A new date format since day 0001. Example 1: Python3 1== import random import matplotlib.pyplot as plt import matplotlib.dates as mdates # generate some random data # for approx 5 yrs random_data = [float(random.randint(1487517521, 14213254713)) for _ in range(1000)] # convert the epoch format to # matplotlib date format mpl_data = mdates.epoch2num(random_data) # plotting the graph fig, axes = plt.subplots(1, 1) axes.hist(mpl_data, bins = 51, color ='green') locator = mdates.AutoDateLocator() axes.xaxis.set_major_locator(locator) axes.xaxis.set_major_formatter(mdates.AutoDateFormatter(locator)) plt.show() Output: Example 2: Python3 1== from tkinter import * from tkinter import ttk import time import matplotlib import queue from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk from matplotlib.figure import Figure import matplotlib.animation as animation import matplotlib.dates as mdate root = Tk() graphXData = queue.Queue() graphYData = queue.Queue() def animate(objData): line.set_data(list(graphXData.queue), list(graphYData.queue)) axes.relim() axes.autoscale_view() figure = Figure(figsize =(5, 5), dpi = 100) axes = figure.add_subplot(111) axes.xaxis_date() line, = axes.plot([], []) axes.xaxis.set_major_formatter(mdate.DateFormatter('%H:%M')) canvas = FigureCanvasTkAgg(figure, root) canvas.get_tk_widget().pack(side = BOTTOM, fill = BOTH, expand = True) for cnt in range (600): graphXData.put(matplotlib.dates.epoch2num(time.time()-(600-cnt))) graphYData.put(0) ani = animation.FuncAnimation(figure, animate, interval = 1000) root.mainloop() Output: Comment More infoAdvertise with us Next Article Matplotlib.dates.epoch2num() in Python R RajuKumar19 Follow Improve Article Tags : Python Write From Home Python-Library Python-matplotlib Practice Tags : python Similar Reads Matplotlib.dates.datestr2num() in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.dates.datestr2num() The matplotlib.dates.datestr2num() function is used to co 2 min read Matplotlib.dates.drange() in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.dates.drange() The matplotlib.dates.drange() function returns a sequence of e 2 min read Matplotlib.axes.Axes.plot_date() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.pyplot.plot_date() function in Python Matplotlib is a module package or library in Python which is used for data visualization. Pyplot is an interface to a Matplotlib module that provides a MATLAB-like interface. The matplotlib.pyplot.plot_date() function is like the regular plot() function, but it's tailored for showing data over dates 3 min read Matplotlib.dates.DateFormatter class in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Matplotlib.dates.DateFormatter The matplotlib.dates.DateFormatter class is used to forma 2 min read Like