Hi, I am new to python with some coding experience. I am trying to write a Pythonista script to read excel data from two columns and plot one of the columns data on the x-axis and the other columns data on the y-axis.
Forum Archive
Read and plot data from excel
https://automatetheboringstuff.com/2e/chapter13/
Thanks for the quick reply. I am still struggling, i am getting a file not found error. This is my script so far.
import os
import numpy as np
import matplotlib.pyplot as plt
import openpyxl
wb = openpyxl.load_workbook('Prac4.xlsx')
sheet = wb['Tstat']
I forgot to state that I am working on an iPad using Pythonista.
@Roscoe
i do apollogise for the large code dump. this was my first python project. it wont run without some other files but the openpyxl is good to ref. i was recieving data fom employees and generating a WorkOrder/FieldTicket. it worked wonderfully but i do some cell/sheet formatting and i add an image (was the hardest to figure out lol) and some other stuff. your welcome to pick it apart. i didnt remove anything only cuz you said your New to Pythonista and there is good amount of ui classes in there aswell. i hope it helps even a little..
import openpyxl, ui, webbrowser
from openpyxl.drawing.image import Image
from openpyxl import cell, chart, chartsheet, comments, compat, constants, descriptors, drawing, formatting, formula, here, json, load_workbook, os, packaging, pivot, reader, src, src_file, styles, utils, workbook, worksheet, writer, xml
testing = False
def SavePreviousMaterials(items):
from json import dump
data = dict({'Data_PreMaterials':items})
with open('DATA/DataPreMaterials.json', 'w') as json_file:
json.dump(data, json_file)
def LoadPreviousMaterials():
pass
'''from json import load
with open('DATA/DataPreMaterials.json', 'r') as json_file:
data = json.load(json_file)
return data['Data_PreMaterials']'''
StoredMaterials = LoadPreviousMaterials()
_jd_cfg=dict()
_jd_cfg['max_width']= 80
_jd_cfg['']= None
_jd_cfg['white_space']= ' '
_jd_cfg['indention_size']= 2
_jd_cfg['paragraph_spacing']= 2
_jd_cfg['formating_indent']= str(' ' * _jd_cfg['indention_size'])
_jd_start = f'Crew arrived to location and performed a safety inspection. After walk through was completed crew prepared tools and Materials. '
_jd_delay = f' Heavy Traffic on Hw128 causing a delay in transit.'
presetDict={
'Company':'Owl'.upper(),
'Rep':'Cody york'.title(),
'Lease':'COG, Gunner tie-in',
'Miles':'75',
'THours':'2',
'Labor':'4',
'JobDisc':f' Arrived to location and completed a JSA. dug out trench for conduit containment. dug out hole for fi-box post. ran conduit from fi-box to devices (1 FIT, 1 PIT). filled trench and leveled conduit. poured concrete to secure post. ran conduit from fi-box to Battery box. pulled wire for power and devices. assymboled Antennae pole and mounted. installed PIT on provided 1/2in port. cleaned location of trash and materials. picked up tools. headed to town. extra time taken due to road condition and trafic on 128.'}
ft = 'ft'
inch = 'in'
ea = 'ea'
def cm(amt, mes, dim, dis):
if amt is not 0:
add_pre_mat(f'{amt}{mes}', f'{dim} {dis}')
StoredMaterials = []
gray = '#f0f0f0'
lightgray= '#fdfdfd'
darkgray = '#bababa'
black = '#4b4b4b'
green = '#069f13'
lightgreen = '#83ba88'
red = '#be5555'
presetMaterials=[]
def add_pre_mat(a, d):
if len(presetMaterials) < 25:
presetMaterials.append((a, d))
add_pre_mat(f'{30}{ft}', f'1/2{inch} {"conduit emt riggid npt".upper()}')
add_pre_mat(f'{10}{ft}', f'2{inch} {"conduit emt riggid npt".upper()}')
add_pre_mat(f'{10}{ft}', f'1{inch} {"conduit emt riggid npt".upper()}')
add_pre_mat(f'{8}{ft}', f'1/2{inch} {"fmt flex seal-tight".upper()}')
add_pre_mat(f'{35}{ft}', f'18{"awg"} {"belson 18-4 wire std".upper()}')
add_pre_mat(f'{10}{ft}', f'12{"awg"} {"Single wire Red".upper()}')
add_pre_mat(f'{10}{ft}', f'12{"awg"} {"Single wire White".upper()}')
add_pre_mat(f'{4}{ft}', f'16{"awg"} {"Single wire Green".upper()}')
add_pre_mat(f'{35}{ft}', f'18{"awg"} {"18-2 wire".upper()}')
add_pre_mat(f'{4}{ea}', f'1/2{inch} {"fmt flex fitting".upper()}')
add_pre_mat(f'{1}{ea}', f'1/2{inch} {"conduit seal fitting riggid npt".upper()}')
add_pre_mat(f'{1}{ea}', f'1/2{inch} {"grt conduit body box HE riggid npt".upper()}')
add_pre_mat(f'{1}{ea}', f'1/2{inch} {"hex conduit plug riggid npt".upper()}')
add_pre_mat(f'{1}{ea}', f'1/2{inch} {"myr-hub containment connection fitting".upper()}')
add_pre_mat(f'{1}{ea}', f'1/2{inch} {"conduit fastening strap".upper()}')
add_pre_mat(f'{2}{ea}', f'1{inch} {"conduit fastening strap".upper()}')
add_pre_mat(f'{1}{ea}', f'4{inch} {"vinel bury tape".upper()}')
add_pre_mat(f'{1}{ea}', f'{""} {"omni directional LTE band Antennea".upper()}')
add_pre_mat(f'{1}{ea}', f'{""} {"static serge protector polly phazer".upper()}')
add_pre_mat(f'{1}{ea}', f'25{"ft"} {"200LMR antennea cable".upper()}')
add_pre_mat(f'{2}{ft}', f'{"deep"} {"slotted unistrut".upper()}')
add_pre_mat(f'{1}{ea}', f'50{"lbs"} {"quick dry concrete".upper()}')
add_pre_mat(f'{1}{ea}', f'{""} {"fi-box containment".upper()}')
add_pre_mat(f'{1}{ea}', f'0-300{"psi"} {"pressure transmitter".upper()}')
add_pre_mat(f'{1}{ea}', f'1/2{inch} {"needle valve with block and bleed".upper()}')
def add_PreviousMaterial(key, val):
return
for sec in StoredMaterials:
if sec[0] is key:
if val in sec[1]:
return
else:
sec[1].append(val)
if sec[0] is StoredMaterials[-1][0] and sec[0] is not key:
return
def getStoredMaterials(key):
for sec in StoredMaterials:
if sec[0] is key:
return sec[1]
def build_mat_save(items):
for x in items:
v=x[1]
if v in StoredMaterials:
print(f'{v} already stored!')
else:
StoredMaterials.append(v)
SavePreviousMaterials(StoredMaterials)
Templet = 'WO_2020.xlsx'
wb = load_workbook(Templet)
ws = wb.active
maxDiscLineSize = 73
for x in range(11):
ws.row_dimensions[x+12].hidden = True
def set_format():
from openpyxl.styles import Border, Side, Font, Alignment
thin = Side(border_style="thin", color='000000')
Brdr = Border(top=thin, left=thin, right=thin, bottom=thin)
fnt = Font(name='Arial', size=10, bold=False, italic=False, vertAlign=None, underline='none', strike=False, color='000000')
fnt13 = Font(name='Arial', size=13, bold=False, italic=False, vertAlign=None, underline='none', strike=False, color='000000')
colums='ABCDEFGH'
for col in colums:
for row in range(1, 62):
cell= f'{col}{row}'
if row > 1:
ws[cell].font = fnt
ws[cell].border = Brdr
ws['A11'].font = fnt13
Cells = []
_date = None
Date = ws['B6']
_company = None
Company = ws['E6']
Cells.append(Company)
_lease = None
Lease = ws['E7']
Cells.append(Lease)
_rep = None
Rep = ws['E8']
Cells.append(Rep)
_job_disc = None
JobDisc = ws['A11']
Cells.append(JobDisc)
Materials = [(ws[f'A{i}'], ws[f'B{i}']) for i in range(25, 51)]
_truck= 'Truck #6'
Truck = ws['A54']
_trailer = 'Trailer ET-3'
Trailer = ws['A55']
_T_miles = None
T_Miles = ws['C54']
Total_T_Miles = ws['C61']
Cells.append(T_Miles)
_T_Hrs = None
T_Hrs = ws['D54']
Total_T_Hrs = ws['D61']
Cells.append(T_Hrs)
_pusher = 'Roger Richards'
_Lbr_Hrs = None
Pusher = ws['E54']
Pusher_Lbr = ws['H54']
Cells.append(Pusher_Lbr)
_hand1 = 'Stephen Frey'
Hand1 = ws['E55']
Hand1_Lbr = ws['H55']
_hand2 = 'Pete Trujillo'
Hand2 = ws['E56']
Hand2_Lbr = ws['H56']
Total_Lbr = ws['H61']
for_pace=dict()
for_pace["date"]=Date
for_pace["county"]="Lea"
for_pace["company"]=Company
for_pace["rep"]=Rep
for_pace["location"]=Lease
for_pace["pusher:name"]=Pusher
for_pace["lead-hand:name"]=Hand1
for_pace["tool-hand:name"]=Hand2
for_pace["pusher:hours"]=Pusher_Lbr
for_pace["lead-hand:hours"]=Hand1_Lbr
for_pace["tool-hand:hours"]=Hand2_Lbr
for_pace["truck:id"]=Truck
for_pace["trailer:id"]=Trailer
for_pace["truck:miles"]=Total_T_Miles
for_pace["job-desc"]=JobDisc
def resize_job_disc(txt, ml=maxDiscLineSize):
n = 11
for x in range(len(txt)):
if x%ml == 0:
n += 1
ws.row_dimensions[n].hidden = False
def set_preset_Vars():
Truck.value = _truck
Trailer.value=_trailer
Pusher.value = _pusher
Hand1.value = _hand1
Hand2.value = _hand2
Hand1_Lbr.value = Pusher_Lbr.value
Hand2_Lbr.value = Pusher_Lbr.value
Total_Lbr.value = Pusher_Lbr.value
Total_T_Miles.value = T_Miles.value
Total_T_Hrs.value = T_Hrs.value
class IMG:
def __init__(ns):
ns.path='tl_logo.png'
def __enter__(ns):
ns=Image(ns.path)
ns.height=ns.height - 250
ns.width=ns.width - 1400
ws.add_image(ns, 'A1')
def __exit__(ns,exc_type=None, exc_value=None, traceback=None):
del ns
def set_logo():
with IMG() as img:
return
def finalize():
from console import open_in
if testing:
fn = 'repository/tickets/test.xlsx'
else:
fn = f'repository/tickets/{Date.value}_{Company.value}_{Lease.value}.xlsx'
import clipboard
clipboard.set(f'{Date.value} {Company.value} {Lease.value}')
wb.save(fn)
wb.close()
#from Pace.FT_A01 import TICKET_FORM as ft
open_in(fn)
w,h = ui.get_screen_size()
button_size = (150, 40)
label_size = (200, 20)
border = (1, black, 0)
buffer = 20
Font = ('American Typewriter', 14)
def Button(values):
ns=ui.Button()
ns.x, ns.y, ns.title, ns.action, ns.tint_color = values
ns.width, ns.height = button_size
ns.border_width, ns.border_color, ns.corner_radius = border
return ns
def Button2(values, size):
ns=ui.Button()
ns.x, ns.y, ns.title, ns.action, ns.background_color = values
ns.tint_color = black
ns.width, ns.height = size
ns.border_width, ns.border_color, ns.corner_radius = border
return ns
class DateField:
def __init__(ns, v):
ns.dp = ui.DatePicker()
ns.dp.action = ns.SetDate
ns.dp.background_color = darkgray
ns.dp.border_color = black
ns.dp.border_width = 1
ns.dp.mode = ui.DATE_PICKER_MODE_DATE
ns.dp.frame = (w/2-140, 100, 280, 150)
for_paceated = None
v.add_subview(ns.dp)
def SetDate(ns, sender):
import datetime
dt= sender.date
dt= dt.strftime('%m-%d-%y')
Date.value = str(dt)
for_paceated = str(dt)
def GetDate(ns):
if for_paceated is None:
dt= ns.dp.date
dt= dt.strftime('%m-%d-%y')
return ' ' + str(dt)
else:
return ' ' + for_paceated
class Field:
def __init__(ns,name, v, sec, y, lt,txt='',font=Font , tfw = 200, tfh = 30, kb= ui.KEYBOARD_DEFAULT):
ns.l=ui.Label()
ns.l.y, ns.l.text, ns.l.font = y, lt + ':', font
ns.l.width, ns.l.height = label_size
if sec is 1:
ns.l.x = buffer + 10
else:
ns.l.x = w - tfw - buffer
ns.name=name
ns.tf=ui.TextField()
ns.tf.keyboard_type = kb
ns.tf.text = txt
ns.tf.x, ns.tf.y, ns.tf.placeholder, ns.tf.font = ns.l.x -10, y+ns.l.height+5, lt, font
ns.tf.width, ns.tf.height = tfw+10, tfh
ns.x = ns.l.x - 10
ns.y = y
ns.width = ns.tf.width
ns.height = ns.l.height+ns.tf.height+10
v.add_subview(ns.l)
v.add_subview(ns.tf)
def Width(ns): return ns.width
def Next(ns): return ns.y + ns.height + 10
def Height(ns): return ns.height
def Value(ns): return ns.tf.text
def Set_Text(ns, txt): ns.tf.text=txt
class CrewField:
def __init__(ns, v, y):
ns.f=ui.View()
ns.f.y= y
ns.f.width=195
ns.f.height=200
ns.f.x = w - ns.f.width - buffer
ns.f.name= 'CREW'
ns.f.border_color= black
ns.f.border_width= 1
ns.lt=ui.Label(x=0,y=5,width=200,height=30,font=Font,text='___________CREW___________')
ns.l1=ui.Label(x=35,y=40,width=300,height=40,font=Font,number_of_lines=2, text=f'Pusher:\n\t{_pusher}')
ns.l2=ui.Label(x=35,y=ns.l1.y+45 ,width=300,height=40,font=Font,number_of_lines=2, text=f'Lead Hand: \n\t{_hand1}')
ns.l3=ui.Label(x=35,y=ns.l2.y +45 ,width=300,height=40,font=Font,number_of_lines=2, text=f'Tool Hand:\n\t{_hand2}')
ns.f.add_subview(ns.lt)
ns.f.add_subview(ns.l1)
ns.f.add_subview(ns.l2)
ns.f.add_subview(ns.l3)
v.add_subview(ns.f)
def GetCrew(ns): return _pusher, _hand1, _hand2
class FieldTextView:
def __init__(ns,name, v, x, y, lt, font=Font , tfw = 500, tfh = 200, kb= ui.KEYBOARD_DEFAULT):
ns.l=ui.Label()
ns.l.x, ns.l.y, ns.l.text, ns.l.font = buffer + 10, y, lt + ':', font
ns.l.width, ns.l.height = label_size
ns.name=name
ns.tf=ui.TextView()
ns.tf.keyboard_type = kb
ns.tf.x, ns.tf.y, ns.tf.font = buffer, y+ns.l.height+5, font
ns.tf.border_color=black
ns.tf.border_width=1
ns.tf.background_color = lightgray
ns.tf.text = f' Crew arrived to location and performed a safety inspection. After walk through was completed crew prepared tools and Materials. '
ns.tf.alignment = ui.ALIGN_LEFT
ns.tf.shows_horizontal_scroll_indicator = False
ns.tf.width, ns.tf.height = tfw, tfh
ns.x = x
ns.y = y
ns.width = ns.tf.width
ns.height = ns.l.height+ns.tf.height+10
v.add_subview(ns.l)
v.add_subview(ns.tf)
def Width(ns): return ns.width
def Next(ns): return ns.y + ns.height + 10
def Height(ns): return ns.height
def Value(ns): return ns.tf.text
def Set_Text(ns, txt):
ns.tf.text=txt
class MaterialPreviousMaterialsView(ui.View):
def __init__(ns, name, superview):
ns.PreviousMaterials = LoadPreviousMaterials()
ns.x= superview.width-300-5
ns.y = 45
ns.width = 300
ns.height = 350
ns.border_color = black
ns.border_width = 0
ns.ds = ui.ListDataSource(StoredMaterials)
ns.background_color = None
ns.tv = ui.TableView()
ns.tv.data_source = ns
ns.tv.delegate = ns
ns.tv.allows_multiple_selection = False
ns.tv.allows_selection = True
ns.tv.row_height = 20
ns.tv.always_bounce_vertical = False
ns.tv.bg_color = darkgray
ns.tv.tint_color = darkgray
ns.tv.border_color = black
ns.tv.border_width = 1
ns.tv.frame = (0, 30, 300, 320)
ns.btn = ui.Button()
ns.btn.background_color= red
ns.btn.border_color, ns.btn.border_width = black, 1
ns.btn.enabled = False
ns.btn.title = 'Add'
ns.btn.tint_color = black
ns.btn.width, ns.btn.height = 75, 25
ns.btn.x, ns.btn.y = 10, 3
ns.btn.action = ns.add_recent_item
ns.recent_value = None
ns.add_subview(ns.btn)
ns.add_subview(ns.tv)
superview.add_subview(ns)
def add_recent_item(ns, sender):
ns.superview.AddRecent(ns.recent_value)
def tableview_did_select(ns, tableview, section, row):
ns.recent_value = ns.PreviousMaterials[row]
ns.btn.enabled = True
ns.btn.background_color= lightgreen
def tableview_did_deselect(ns, tableview, section, row):
ns.btn.enabled = False
ns.btn.background_color= red
def tableview_number_of_sections(ns, tableview):
return 1
def tableview_number_of_rows(ns, tableview, section):
return len(ns.PreviousMaterials)
def tableview_cell_for_row(ns, tableview, section, row):
cell = ui.TableViewCell()
cell.text_label.text = ns.PreviousMaterials[row]
cell.background_color = gray
cell.border_color = black
cell.border_width = .5
cell.selectable = True
return cell
def tableview_title_for_header(ns, tableview, section):
return 'Recently Used Materials'
def tableview_can_delete(ns, tableview, section, row):
return False
def tableview_can_move(ns, tableview, section, row):
return False
def tableview_delete(ns, tableview, section, row):
pass
def tableview_move_row(ns, tableview, from_section, from_row, to_section, to_row):
pass
class MatView(ui.View):
def __init__(ns, v, x=20, y=550):
ns.x, ns.y = x, y
ns.width, ns.height = 728, 400
ns.border_color, ns.border_width = black, 1
v.add_subview(ns)
Hdr1=ui.Label(font=(Font[0], 24),text='Materials',frame=(ns.width/2-60, 18, 120, 25))
Hdr2=ui.Label(font=(Font[0],12),text='<•>'*36,frame=(4,35,ns.width,15))
Hdr2.text_color = darkgray
ns.add_subview(Hdr1)
ns.add_subview(Hdr2)
ns.edit_btn = Button2((50,4,'Edit', ns.remove_last, lightgreen),(100, 35))
ns.add_subview(ns.edit_btn)
ns.add_subview(Button2((ns.width/6*5,4,'ADD', ns.Add, lightgreen),(75, 35)))
ns.mhv = MaterialPreviousMaterialsView('PreviousMaterials', ns)
ns.range = (25, 51)
ns.curAmnt = '1'
ns.curDisc = '1/2 '
ns.mats=[]
ns.checkPresets()
ns.tv = ui.TableView()
ns.tv.data_source = ns
ns.tv.data_source.items = ns.mats
ns.tv.delegate = ns
ns.tv.allows_multiple_selection = False
ns.tv.allows_selection = True
ns.tv.row_height = 30
ns.tv.tint_color = green
ns.tv.always_bounce_vertical = False
ns.tv.bg_color = darkgray
ns.tv.tint_color = darkgray
ns.tv.border_color = black
ns.tv.border_width = 1
ns.tv.frame = (5, 75, 410, 320)
ns.add_subview(ns.tv)
def AddRecent(ns, item):
ns.curDisc = item
ns.Add(ns)
def remove_last(ns, sender):
ns.tv.editing = not ns.tv.editing
if ns.tv.editing:
ns.edit_btn.background_color = red
else:
ns.edit_btn.background_color = lightgreen
def textfield_did_change(ns, textfield):
if ns.amnt.text is '' or ns.disc.text == '':
ns.subnewbtn.enabled = False
else:
ns.subnewbtn.enabled = True
ns.curAmnt = ns.amnt.text
ns.curDisc = ns.disc.text
def addNew(ns):
if len(ns.mats) < 25:
checklist=list(['ft',"'",'feet','in','"','inches','ea','each'])
for x in checklist:
if x in ns.curAmnt:
return
if x==checklist[-1] and x not in ns.curAmnt:
ns.curAmnt= f'{ns.curAmnt}ea'
ns.mats.append((ns.curAmnt, ns.curDisc))
ns.curAmnt, ns.curDisc = '1', '1/2 '
ns.tv.reload_data()
def checkPresets(ns):
if len(presetMaterials) > 0:
for mat in presetMaterials:
ns.mats.append(mat)
def submit(ns, sender):
if ns.curDisc != None:
ns.addNew()
sender.superview.close()
def Add(ns, sender):
ns.am=ui.View(frame=(0,0,445,50))
ns.am.background_color=gray
ns.am.border_color, ns.am.border_width=black, 1
ns.am.corner_radius = 15
ns.subnewbtn = Button2((ns.am.width-50,5,'√',ns.submit, green),(40, 40))
ns.am.add_subview(ns.subnewbtn)
ns.amnt=ui.TextField(frame=(10, 5, 70, 40))
ns.amnt.delegate = ns
ns.amnt.name='amount'
ns.amnt.text = ns.curAmnt
ns.amnt.keyboard_type= ui.KEYBOARD_NUMBERS
ns.amnt.font = Font
ns.amnt.placeholder= '!!!'
ns.amnt.border_color, ns.amnt.border_width= black, 1
ns.disc=ui.TextField(frame=(85, 5, 300,40))
ns.disc.delegate= ns
ns.disc.name='disc'
ns.disc.font=Font
ns.disc.text = ns.curDisc
ns.disc.placeholder= '!!!'
ns.disc.border_color, ns.disc.border_width = black, 1
ns.am.add_subview(ns.amnt)
ns.am.add_subview(ns.disc)
ns.am.present('sheet', hide_title_bar=True)
def shuffle(ns, list, from_row, to_row):
item = list[from_row]
del list[from_row]
list.insert(to_row, item)
return list
def tableview_did_select(ns, tableview, section, row):
pass
def tableview_did_deselect(ns, tableview, section, row):
pass
def tableview_number_of_sections(ns, tableview):
return 1
def tableview_number_of_rows(ns, tableview, section):
return len(ns.mats)
def tableview_accessory_button_tapped(ns, tableview, section, row):
ns.superview.AddRecent(row.text_label.text)
def tableview_cell_for_row(ns, tableview, section, row):
s1 = ns.mats[row][0]
s2 = ns.mats[row][1]
text = s1 + ', ' + s2
cell = ui.TableViewCell()
cell.text_label.text = text
cell.background_color = gray
cell.border_color = black
cell.border_width = 0.5
cell.selectable = True
return cell
def tableview_title_for_header(ns, tableview, section):
return 'New Materials List'
def tableview_can_delete(ns, tableview, section, row):
return True
def tableview_can_move(ns, tableview, section, row):
return True
def tableview_delete(ns, tableview, section, row):
del ns.mats[row]
tableview.reload_data()
def tableview_move_row(ns, tableview, from_section, from_row, to_section, to_row):
ns.mats = ns.shuffle(ns.mats, from_row, to_row)
class Form(ui.View):
def __init__(ns):
ns.Fields = []
ns.background_color= gray
ns.width, ns.height = ui.get_screen_size()
ns.add_subview(Button((w/2, 35, 'Close', ns.quit, red)))
ns.add_subview(Button((w/2 - 155, 35, 'Submit', ns.submit, green)))
ns.Date = DateField(ns)
ns.Company = Field('Company', ns, 1, 100, 'Company', txt='MBE')
ns.Rep = Field('Rep', ns, 1, ns.Company.Next(), 'Company Rep', kb = ui.KEYBOARD_NAME_PHONE_PAD,txt='Zack Jewel')
ns.Lease = Field('Lease', ns, 1, ns.Rep.Next(), 'Location', tfw = 350)
ns.JobD = FieldTextView('JobDisc', ns, 1, ns.Lease.Next(), 'Job Discription')
ns.TMiles = Field('Miles', ns, 400, 100 , 'Travel Miles', kb = ui.KEYBOARD_NUMBERS)
ns.THours = Field('THours', ns, 400, ns.TMiles.Next(), 'Travel Hours', kb = ui.KEYBOARD_NUMBERS)
ns.Labor= Field('Labor', ns, 400, ns.THours.Next(), 'Labor Hours', kb = ui.KEYBOARD_NUMBERS)
ns.Crew = CrewField(ns, ns.Labor.Next() + 25)
ns.Fields.append(ns.Company)
ns.Fields.append(ns.Lease)
ns.Fields.append(ns.Rep)
ns.Fields.append(ns.JobD)
ns.Fields.append(ns.TMiles)
ns.Fields.append(ns.THours)
ns.Fields.append(ns.Labor)
ns.mv=MatView(ns)
ns.add_subview(ns.mv)
def quit(ns, sender):
ns.close()
def end(ns, sender):
build_mat_save(ns.mv.mats)
set_format()
set_logo()
finalize()
ns.close()
def submit(ns, sender):
for i in range(0,7):
Cells[i].value=ns.Fields[i].Value()
set_preset_Vars()
Date.value = ns.Date.GetDate()
for i in range(0,len(ns.mv.mats)):
Materials[i][0].value = ns.mv.mats[i][0]
Materials[i][1].value = ns.mv.mats[i][1]
add_PreviousMaterial('material', ns.mv.mats[i][1])
ws.row_dimensions[i+25].hidden = False
resize_job_disc(ns.JobD.Value())
ns.end(sender)
def preset(ns, item, value):
ns.item.Set_Text(value)
def Presets(l, d):
for key, val in d.items():
for v in l:
if v.name == key:
v.Set_Text(val)
cm(0, ft, '', '')
form = Form()
Presets(form.Fields, presetDict)
def OpenForm():
pass
form.present('full_screen', hide_title_bar=True)
@Roscoe said:
Thanks for the quick reply. I am still struggling, i am getting a file not found error. This is my script so far.
import os
import numpy as np
import matplotlib.pyplot as plt
import openpyxlwb = openpyxl.load_workbook('Prac4.xlsx')
sheet = wb['Tstat']
if you know for sure the filename is good ty setting sheet with wb.get_sheet_by_name()
@Roscoe
I have created test file and sheet with same name. how is the data layed out in your sheet? and are you trying to chart the plot on the xlsx doc or just in pythonista?
@stephen
Thanks for the help. I managed to plot the data (I just wanted to chart the plot in Pythonista). I used the following code.
import os
import matplotlib.pyplot as plt
import openpyxl
from openpyxl import cell, chart, chartsheet, comments, compat, constants, descriptors, drawing, formatting
wb = openpyxl.load_workbook('/private/var/mobile/Containers/Shared/AppGroup/29254C8A-D386-4CDC-B278-AAA57C080F82/Pythonista3/Documents/Prac4.xlsx')
sheet = wb['Tstat']
for i in range(1,sheet.max_row,1):
x1data = sheet.cell(row=i,column=1).value
y1data = sheet.cell(row=i,column=2).value
x2data = sheet.cell(row=i,column=4).value
y2data = sheet.cell(row=i,column=5).value
x3data = sheet.cell(row=i,column=7).value
y3data = sheet.cell(row=i,column=8).value
plt.plot(x1data,y1data,'r^',x2data,y2data,'bo',x3data,y3data,'mv')
plt.show()
Although I could only show points on the plot and couldn’t create a line.
@Roscoe said:
@stephen
Thanks for the help. I managed to plot the data (I just wanted to chart the plot in Pythonista). I used the following code.
import os
import matplotlib.pyplot as plt
import openpyxl
from openpyxl import cell, chart, chartsheet, comments, compat, constants, descriptors, drawing, formattingwb = openpyxl.load_workbook('/private/var/mobile/Containers/Shared/AppGroup/29254C8A-D386-4CDC-B278-AAA57C080F82/Pythonista3/Documents/Prac4.xlsx')
sheet = wb['Tstat']for i in range(1,sheet.max_row,1):
x1data = sheet.cell(row=i,column=1).value
y1data = sheet.cell(row=i,column=2).value
x2data = sheet.cell(row=i,column=4).value
y2data = sheet.cell(row=i,column=5).value
x3data = sheet.cell(row=i,column=7).value
y3data = sheet.cell(row=i,column=8).value
plt.plot(x1data,y1data,'r^',x2data,y2data,'bo',x3data,y3data,'mv')plt.show()
Although I could only show points on the plot and couldn’t create a line.
Following from matplotlib.org
Plot y versus x as lines and/or markers.
Call signatures:
plot([x], y, [fmt], *, data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
Copy to clipboard
The coordinates of the points or line nodes are given by x, y.
The optional parameter fmt is a convenient way for defining basic formatting like color, marker and linestyle. It's a shortcut string notation described in the Notes section below.
>>> plot(x, y) # plot x and y using default line style and color
>>> plot(x, y, 'bo') # plot x and y using blue circle markers
>>> plot(y) # plot y using x as index array 0..N-1
>>> plot(y, 'r+') # ditto, but with red plusses
Copy to clipboard
You can use Line2D properties as keyword arguments for more control on the appearance. Line properties and fmt can be mixed. The following two calls yield identical results:
>>> plot(x, y, 'go--', linewidth=2, markersize=12)
>>> plot(x, y, color='green', marker='o', linestyle='dashed',
... linewidth=2, markersize=12)
Copy to clipboard
When conflicting with fmt, keyword arguments take precedence