0

Hello I am attempting to write a program that allows the plotting of the graph from various data sets from a excel database.(The x axis is a fixed set of values while the data values from other columns can be selected). However, the graph that is plotted only contains the axes of the graph, while the data points are completely missing. The code I have used is as such:

import xlrd
import matplotlib.pyplot as plt
from matplotlib.figure import *
loc = ("C:\\Users\\yeoho\\DCO_Raw_Data.xlsx")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0,0)
x = [[sheet.cell_value(r,0)]for r in range(6,sheet.nrows)]
checkOn = True
while checkOn:
    FileName = [[sheet.cell_value(0,c)]for c in range(1,13)]
    print(FileName)
    print("Enter the Integer (1-n) corresponding to the file name that you would like to plot")
    z = int(input())
    y = [[sheet.cell_value(r,z)]for r in range(6,sheet.nrows)]
    fig = plt.figure()
    ax = fig.add_subplot(111)
    assert len(x) == len(y)
    for i in range(len(x)):
        plt.plot(x[i],y[i],color='black')
        plt.show()
        break

The code in lines 16-21 were taken from another stackoverflow page. How to plot two lists of tuples with Matplotlib The original code did not have a color parameter but I have found out that that is not the source of the issue.

I am unsure of what the issue here is. Thank you for taking your time to read this and I hope you can help me with this issue.

ItsASnake
  • 1
  • 2
  • The last `break` terminates the loop after the first iteration. Remove it. Also, unindent the last `plt.show()`. Your code has many other issues, too. – DYZ Jan 09 '20 at 04:24
  • A few thing: Asterisk imports are a bad idea, I strongly recommend not using them. Why are you using the xlrd library? Variable and function names should follow the `lower_case_with_underscores` style. Assert statements should only be used for debugging purposes. – AMC Jan 09 '20 at 04:30
  • Hello @DYZ are there multiple sources of error that would result in the aforementioned problem? I apologise as I am not proficient in Python having only picked it up a while back. Would greatly appreciate if you could point out the issues. Thank you! – ItsASnake Jan 09 '20 at 04:34
  • @AMC `xlrd` is used to open a spreadsheet. – DYZ Jan 09 '20 at 04:36
  • Hi @AMC I was not entirely sure how to access excel files from Python and searched it up today. Are the issues you pointed out critical flaws in the programme? Sorry as I am not proficient in Python having only picked it up a while back. Thank you for taking your time! – ItsASnake Jan 09 '20 at 04:38
  • @ItsASnake xlrd is currently unmaintained, and should really only be used to handle the old XLS format. The recommended alternative is openpyxl. – AMC Jan 09 '20 at 04:41
  • Hi @DYZ may I ask if there is anything inherent that would result in matplotlib not plotting out data points? I have applied your adjustments but the resultant graphs still only display the axes. Thank you! – ItsASnake Jan 09 '20 at 04:42
  • But did you remove the `break`? – DYZ Jan 09 '20 at 06:04
  • The break has been removed but every input still results in missing data points, even though the value on the axes changes to fit the data of each set – ItsASnake Jan 09 '20 at 06:13
  • Seems you plot a single point and want it to be displayed as line. But a line needs two points. And a single point would need a marker. – ImportanceOfBeingErnest Jan 09 '20 at 10:42

0 Answers0