Having alot of trouble finding a solution that works when trying to put dates along the xaxis. Im not pulling any data from the internet, all of it is coming from a notepad file at the moment. Many of the solutions i have found give me errors, and the youtube videos i have watched explaining how to do this, all draw in information i think by using urllib.
Fig = Figure(figsize=(10,4), dpi=80)
a = Fig.add_subplot(111)
Fig.subplots_adjust(left=0.1, right=0.974, top=0.9, bottom=0.1)
Fig.patch.set_visible(False)
a.title.set_text('Graph')
a.set_xlabel('Date')
a.set_ylabel('Cost (GBP)')
the code above is the code i currently have to make the graph, before it get overwritten using the code below.
def animate_graph(self, i):
pullData = open('financeData.txt','r').read()
dataList = pullData.split('\n')
xAxisList = []
yAxisList = []
taxList = []
outgoingsList = []
for eachLine in dataList:
if len(eachLine) > 1:
x, y, o= eachLine.split(',')
xAxisList.append(int(x))
yAxisList.append(int(y))
intY = int(y)
taxGraphData = intY * TAXRATE
taxList.append(taxGraphData)
outgoingsList.append(int(o))
a.clear()
a.plot(xAxisList, yAxisList, label='Profits line', color='green')
a.plot(xAxisList, outgoingsList, label='Outgoings line')
a.plot(xAxisList, taxList, label='Tax line')
a.title.set_text('Pyraknight Finance Graph')
a.set_xlabel('Date')
a.set_ylabel('Cost (GBP)')
a.legend()
And then to place the graph onto my frame i have used the code below
canvas = FigureCanvasTkAgg(Fig, graphFrame)
canvas.show()
canvas.get_tk_widget().grid(row=0,column=0,padx=10,pady=10,sticky='nsew')
self.ani = animation.FuncAnimation (Fig, self.animate_graph, interval=1000)
THese are the libraries im importing:
#importing tkinter libraries
import tkinter as tk
from tkinter.ttk import Combobox,Treeview,Scrollbar
#importing matplotlib libraries
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import matplotlib.animation as animation
from matplotlib import style
import matplotlib.dates as mdates
#Other libraries
import hashlib
import sqlite3
import os
import time
import datetime
How would i go about adding dates to my x axis? Thanks in advance, Nas

