Home > Mobile >  Create matplotlib line graph from sqlite table that assigns lines to each name that appears in the t
Create matplotlib line graph from sqlite table that assigns lines to each name that appears in the t

Time:11-23

I have a sqlite table that I would like make a line graph. below is some example code that shows the type of data I am looking to work with:

code:

import sqlite3

conn = sqlite3.connect('sales_sheet.db')
cur = conn.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS sales(id INTEGER PRIMARY KEY NOT NULL, 
            sales_rep TEXT,
            client TEXT,
            number_of_sales INTEGER)""")

case1 = ("Jon","Apple", 5)
case2 = ("Judy","Amazon", 6)
case3 = ("Jon","Walmart", 4)
case4 = ("Don","Twitter", 8)
case5 = ("Don","Walmart", 4)
case6 = ("Judy","Google", 7)
case7 = ("Judy","Tesla", 3)
case8 = ("Jon","Microsoft", 7)
case9 = ("Don", "SpaceX", 5)

insert = """INSERT INTO sales(sales_rep, client, number_of_sales) VALUES(?,?,?)"""

cur.execute(insert, case1)
cur.execute(insert, case2)
cur.execute(insert, case3)
cur.execute(insert, case4)
cur.execute(insert, case5)
cur.execute(insert, case6)
cur.execute(insert, case7)
cur.execute(insert, case8)
cur.execute(insert, case9)

conn.commit()
conn.close()

picture of table: enter image description here

I want the x axis to consist of the numbers in the id column and the y axis to represent the number of sales each rep makes and have a line for each rep mentioned in the table with color coding to represent each sales rep. can anyone tell me how to do this? Thank you in advance.

CodePudding user response:

You can use enter image description here

  • Related