1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

python グラフを色をつけたり -csv-

Posted at

作成したグラフに色や年代を追加

import tkinter
import csv

root = tkinter.Tk()
root.title("売り上げの推移")
ca = tkinter.Canvas(width=800, height=480, bg="white")
ca.pack()

f = open("売り上げデータ.csv",encoding="utf-8")
cr = csv.reader(f)
dat = list(cr)
f.close()

FNT = ("Times New Roman", 12)
bar_x = 40
bar_b = 320
for ye in range(1,6):
    ca.create_rectangle(bar_x, bar_b+5, bar_x+140, bar_b+25, fill="gray", width=0)
    ca.create_text(bar_x+70, bar_b+15, text=dat[0][ye], fill="white", font=FNT)
    ca.create_rectangle(bar_x, bar_b, bar_x+140, bar_b-int(dat[13][ye])/24, fill="skyblue", width=0)    
    for mo in range(1,13):
        h = int(dat[mo][ye])/6
        ca.create_rectangle(bar_x, bar_b, bar_x+6, bar_b-h, fill="blue")
        bar_x = bar_x + 12
root.mainloop()

スクリーンショット 2022-07-15 2.31.36.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?