[Python] Python: How to specify values on axis?

Discussão em 'Python' iniciado por Stack, Julho 13, 2025.

  1. Stack

    Stack Membro Participativo

    This is my first python graph.

    The following question is on plotting students percentage (0-100%). I am trying to set my x-axis values as [0, 10, 20 up to 100] and display bars in the intervals. The problem is the x-axis only gets 5 values and they are unsorted. I have to display data and plot a graph on each column of Excel sheet, that is why I have written the method.

    I have attached this graph which I am getting from following code

    import xlrd as x
    import matplotlib.pyplot as plt1

    excelFile = 'cal1.xls'
    workBook = x.open_workbook(excelFile)
    workSheet = workBook.sheet_by_name("Sheet1")
    rows = workSheet.nrows
    cols = workSheet.ncols

    def getData_Excel(col):

    list = []

    for count in range(1, rows, 1):

    list.append(workSheet.cell_value(count, col))
    print("\nStudent ", count, " : ", list[count-1:count])

    print()

    return list

    print("Students Matric Marks:")

    matricData = [getData_Excel(3)]

    matricLegend = ['Matric %']
    plt1.hist(matricData, histtype = 'bar', color = 'blue', rwidth = 0.8)
    plt1.xlabel('Percentage')
    plt1.ylabel('Number of Students')
    plt1.xticks(range(0, 110, 10))
    plt1.yticks(range(0, 160, 20))
    plt1.title("Matric Marks")
    plt1.legend(matricLegend)
    plt1.show()

    Continue reading...

Compartilhe esta Página