示例#1
0
def example1_simple(saveFiles_):
    """
   In this example, a single-line plot is created:

   .. image:: ../exampleOutput/linePlot_simple.png
       :scale: 50%

   :param saveFiles_: Boolean if True, figures are saved, if False, figures are displayed
   """

    profitData = [[10, 25, 40, 32, 60, 85, 75, 55, 70]]

    months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"]

    filePath = ""
    if (saveFiles_):
        filePath = "linePlot_simple.png"
    crGraphs.createLinePlot(profitData,
                            "Profit so far this year",
                            xTickLabels_=months,
                            xLabel_="Month",
                            yLabel_="Profit (mil. £)",
                            yMin_=0,
                            yMax_=100,
                            filePath_=filePath)
示例#2
0
def example4_boxPlots(saveFiles_):
    """
   In this example, a multi-line plot with box plots is created, without the grid or data point
   connections shown.

   Also, a Willcoxon test is performed find out data points with significant differences between them.
   A \* notation is used next to a month where there is significant difference with p=0.05.
   A \*\* notation is used when there is a significant different with p=0.01.

   .. image:: ../exampleOutput/linePlot_boxPlots.png
       :scale: 50%

   :param saveFiles_: Boolean if True, figures are saved, if False, figures are displayed
   """

    profitData = [[20, 20, 30, 20, 35, 55, 40, 20, 30],
                  [10, 20, 28.5, 12, 25, 53.5, 35, 35, 40]]
    #-- change each data point above to become a list with a normal distribution instead, with median of profitData[i][j]
    profitData = [[
        list(random.standard_normal(30) * 3 + profitData[i][j])
        for j in range(len(profitData[i]))
    ] for i in range(len(profitData))]

    legendLabels = ['Customer sales', 'Stocks']
    months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"]

    style = crGraphStyle.crGraphStyle()
    style.markers = ['s', 's']
    style.colors = ['g', 'r']
    style.lineWidth = 0
    style.gridType = crGraphStyle.GRID_TYPE.NONE
    crGraphs.setStyle(style)

    filePath = ""
    if (saveFiles_):
        filePath = "linePlot_boxPlots.png"
    crGraphs.createLinePlot(profitData,
                            "Profit so far this year",
                            xTickLabels_=months,
                            xLabel_="Month",
                            yLabel_="Profit (mil. £)",
                            yMin_=0,
                            yMax_=80,
                            legendLabels_=legendLabels,
                            showBoxPlots_=True,
                            doWilcoxon_=True,
                            filePath_=filePath)
示例#3
0
def example3_errorBars(saveFiles_):
    """
   In this example, a multi-line plot with error bars is created, with horizontal-only grid shown and with
   data points connected together based on which year quarter they belong to:

   .. image:: ../exampleOutput/linePlot_errorBars.png
       :scale: 50%

   :param saveFiles_: Boolean if True, figures are saved, if False, figures are displayed
   """

    profitData = [[9, 20, 30, 20, 35, 55, 40, 20, 30],
                  [1, 5, 10, 12, 25, 30, 35, 35, 40],
                  [10, 25, 40, 32, 60, 85, 75, 55, 70]]
    #-- change each data point above to become a list with a normal distribution instead, with median of profitData[i][j]
    profitData = [[
        list(random.standard_normal(3) * 5 + profitData[i][j])
        for j in range(len(profitData[i]))
    ] for i in range(len(profitData))]

    legendLabels = ['Customer sales', 'Stocks', 'Total profit']
    months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"]

    filePath = ""
    if (saveFiles_):
        filePath = "linePlot_errorBars.png"

    style = crGraphStyle.crGraphStyle()
    style.markers = ['o', 'o', 's']
    style.colors = ['g', 'c', 'r']
    style.numOfLegendColumns = 3
    style.legendPosition = crGraphStyle.LEGEND_POSITION.UPPER_LEFT
    style.gridType = crGraphStyle.GRID_TYPE.HORIZONTAL
    crGraphs.setStyle(style)

    crGraphs.createLinePlot(profitData,
                            "Profit so far this year",
                            xTickLabels_=months,
                            xLabel_="Month",
                            yLabel_="Profit (mil. £)",
                            yMin_=-20,
                            yMax_=120,
                            legendLabels_=legendLabels,
                            showConfidenceIntervals_=True,
                            xAxisGroupSize_=3,
                            filePath_=filePath)
示例#4
0
def example():
    """
   In this example, figures for the "Using Styles" page are created.
   """

    profitData = [
        [9, 20, 30, 20, 35, 55, 40, 20, 30],
        [1, 5, 10, 12, 25, 30, 35, 35, 40],
        [10, 25, 40, 32, 60, 85, 75, 55, 70],
    ]

    legendLabels = ['Customer sales', 'Stocks', 'Total profit']
    months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"]

    crGraphs.createLinePlot(profitData,
                            "Profit so far this year",
                            xTickLabels_=months,
                            xLabel_="Month",
                            yLabel_="Profit (mil. £)",
                            yMin_=0,
                            yMax_=100,
                            legendLabels_=legendLabels,
                            filePath_="usingStyles_noStyle.png")

    style = crGraphStyle.crGraphStyle()
    style.markers = ['o', 'd', 's']
    style.colors = ['g', 'c', 'r']
    style.titleFontSize = 40
    style.numOfLegendColumns = 1
    style.gridType = crGraphStyle.GRID_TYPE.MAJOR_HORIZONTAL
    crGraphs.setStyle(style)

    crGraphs.createLinePlot(profitData,
                            "Profit so far this year",
                            xTickLabels_=months,
                            xLabel_="Month",
                            yLabel_="Profit (mil. £)",
                            yMin_=0,
                            yMax_=100,
                            legendLabels_=legendLabels,
                            filePath_="usingStyles_style.png")
示例#5
0
def example2_multiple(saveFiles_):
    """
   In this example, a multi-line plot is created and its custom colours and markers are specified.

   .. image:: ../exampleOutput/linePlot_multi.png
       :scale: 50%

   :param saveFiles_: Boolean if True, figures are saved, if False, figures are displayed
   """

    profitData = [
        [9, 20, 30, 20, 35, 55, 40, 20, 30],
        [1, 5, 10, 12, 25, 30, 35, 35, 40],
        [10, 25, 40, 32, 60, 85, 75, 55, 70],
    ]

    legendLabels = ['Customer sales', 'Stocks', 'Total profit']
    months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"]

    style = crGraphStyle.crGraphStyle()
    style.markers = ['o', 'o', 's']
    style.colors = ['g', 'c', 'r']
    crGraphs.setStyle(style)

    filePath = ""
    if (saveFiles_):
        filePath = "linePlot_multi.png"
    crGraphs.createLinePlot(profitData,
                            "Profit so far this year",
                            xTickLabels_=months,
                            xLabel_="Month",
                            yLabel_="Profit (mil. £)",
                            yMin_=0,
                            yMax_=100,
                            legendLabels_=legendLabels,
                            filePath_=filePath)
示例#6
0
def example(saveFiles_):
    """
   In this example, plot images for a broken line plot are created:

   :param saveFiles_: Boolean if True, figures are saved, if False, figures are displayed
   """

    data = [
        [
            10, 12, 25, 32, 25, 57, 44, 54, 62, 60, 44, 35, 51, 62, 84, 280,
            305, 312, 309, 323
        ],
    ]

    data = [[
        list(random.standard_normal(10) * 2 * j + data[i][j])
        for j in range(len(data[i]))
    ] for i in range(len(data))]

    filePathStandardPlot = ""
    filePathBottomPlot = ""
    filePathTopPlot = ""
    if (saveFiles_):
        filePathStandardPlot = "brokenLinePlot_standard.png"
        filePathBottomPlot = "brokenLinePlot_bottom.png"
        filePathTopPlot = "brokenLinePlot_top.png"

    #-- get plot parameters for the zoomed in and zoomed out plots
    yMinStandardPlot = 0
    # y min of a plot that would normally be drawn for all data
    yMaxStandardPlot = 400
    # y max of a plot that would normally be drawn for all data
    brokenLineYCoordinate = 100
    # y value at which broken line will be drawn. This value separates the two "zoomedIn" and "zoomedOut" plots
    brokenLineHeightPercentage = 50
    # percentage of the plot height at which the broken line will be drawn

    yMinBottomPlot, yMaxBottomPlot, yMinTopPlot, yMaxTopPlot = crGraphs.getBrokenLinePlotParameters(
        yMinStandardPlot, brokenLineYCoordinate, yMaxStandardPlot,
        brokenLineHeightPercentage)

    style = crGraphStyle.crGraphStyle()
    style.lineWidth = 2
    crGraphs.setStyle(style)

    #-- create the two plots as two separate files, using the y-axis parameters from above
    xTickLabels = [(g + 1) for g in range(len(data[0]))]

    crGraphs.createLinePlot(data,
                            "Population fitness",
                            xTickLabels_=xTickLabels,
                            xLabel_="Generation",
                            yLabel_="Fitness",
                            yMin_=yMinBottomPlot,
                            yMax_=yMaxBottomPlot,
                            yTicksStep_=20,
                            showBoxPlots_=True,
                            filePath_=filePathBottomPlot)
    crGraphs.createLinePlot(data,
                            "Population fitness",
                            xTickLabels_=xTickLabels,
                            xLabel_="Generation",
                            yLabel_="Fitness",
                            yMin_=yMinTopPlot,
                            yMax_=yMaxTopPlot,
                            showBoxPlots_=True,
                            filePath_=filePathTopPlot)

    #-- also create a standard plot for demonstration:
    crGraphs.createLinePlot(data,
                            "Population fitness",
                            xTickLabels_=xTickLabels,
                            xLabel_="Generation",
                            yLabel_="Fitness",
                            yMin_=yMinStandardPlot,
                            yMax_=yMaxStandardPlot,
                            showBoxPlots_=True,
                            filePath_=filePathStandardPlot)