Esempio n. 1
0
def example3_multiFigure(saveFiles_):
   """
   In this example, two figures are created below each other and saved into a single file:

   .. image:: ../exampleOutput/pieChart_large.png
       :scale: 100%

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

   #-- create 1st figure. Make it portait size and use the holdFigure_=True argument to specify that the figure should not be displayed yet
   expenseCategories = ["Rent", "Food", "Travel", "Fun"];
   expenses = [1000, 300, 500, 250];

   style = crGraphStyle.crGraphStyle();
   style.figureSize = (14,6);
   crGraphs.setStyle(style);

   figure1 = crGraphs.createPieChart(expenses, expenseCategories, "Expenses", subPlot_=121, renderFigure_=False);

   #-- create 2nd figure into the figure1 saved previously. Specify the file path to save into.
   countries = ["Germany", "USA", "Canada"];
   numOfCountryVisits = [10, 3, 7];

   filePath = "";
   if (saveFiles_):
      filePath = "pieChart_large.png";
   crGraphs.createPieChart(numOfCountryVisits, countries, showPercentageVals_=True, showActualVals_=False,
      subPlot_=122,figure_=figure1, filePath_=filePath);
Esempio n. 2
0
def example2_customAnnotationsAndColorMap(saveFiles_):
   """
   In this example, a matrix plot with custom annotations and color map is created:

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

   :param saveFiles_: Boolean if True, figures are saved, if False, figures are displayed
   """
   performanceData = [
      [12,11,10,9],
      [11,10,7,6],
      [9,8,6,5],
   ]

   annotations = [ ['poor','poor','good','good'],
      ['poor','poor', 'good', 'excellent'],
      ['good', 'good','excellent','excellent']
   ];

   style = crGraphStyle.crGraphStyle();
   style.figureSize = (16,8);
   style.colorMap = pyplot.cm.get_cmap("Oranges");
   crGraphs.setStyle(style);

   filePath = "";
   if (saveFiles_):
      filePath = "matrixPlot_fullAnnotations.png";

   crGraphs.createMatrixPlot(performanceData, "Cost of fuel for drivers", colorBarLabel_="Fuel cost",
      xLabel_="Driver skill", xTickLabels_=["Terrible","Quite bad","Satisfactory","Good"],
      yLabel_="Engine efficiency", yTickLabels_=["Inefficient","OK","Efficient"],
      annotateValues_=True, annotationValues_=annotations, annotationStringAfter_= "\ncost\nefficiency",
      filePath_=filePath)
Esempio n. 3
0
def example1_simple(saveFiles_):
    """
   In this example, a simple bar plot is created:

   .. image:: ../exampleOutput/barPlot_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 = "barPlot_simple.png"

    style = crGraphStyle.crGraphStyle()
    style.gridType = crGraphStyle.GRID_TYPE.NONE
    crGraphs.setStyle(style)

    crGraphs.createBarPlot(profitData,
                           "Profit so far this year",
                           xTickLabels_=months,
                           xLabel_="Month",
                           yLabel_="Profit (mil. £)",
                           yMin_=0,
                           yMax_=100,
                           filePath_=filePath)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
0
def example2_colors(saveFiles_):
   """
   In this example, the title, colors and font sizes are specified. Percentage values and actual values are also shown:

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

   :param saveFiles_: Boolean if True, figures are saved, if False, figures are displayed
   """
   expenseCategories = ["Rent", "Food", "Travel", "Fun"];
   expenses = [1000, 300, 500, 250];

   style = crGraphStyle.crGraphStyle();
   style.colors = ['yellow','cyan','grey','white'];
   crGraphs.setStyle(style);

   filePath = "";
   if (saveFiles_):
      filePath = "pieChart_colors.png";
   crGraphs.createPieChart(expenses, expenseCategories, "Colors example", showPercentageVals_=True, showShadow_=True, filePath_=filePath);
Esempio n. 7
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")
Esempio n. 8
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)
Esempio n. 9
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)