# Source code for examples.brokenLinePlots

from numpy import random;
from pyCreeper import crGraphs;
from pyCreeper import crGraphStyle;

crGraphs.BASE_FILE_PATH = "../../exampleOutput/";

[docs]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))];

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);

if __name__ == "__main__":

saveFiles = True;

example(saveFiles);
{"ft_lang_label":"__label__en","ft_lang_prob":0.56850344,"math_prob":0.91526634,"size":2438,"snap":"2022-05-2022-21","text_gpt3_token_len":678,"char_repetition_ratio":0.13640098,"word_repetition_ratio":0.074074075,"special_character_ratio":0.26292044,"punctuation_ratio":0.26065162,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.991969,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-26T02:34:40Z\",\"WARC-Record-ID\":\"<urn:uuid:eaf3c1a7-ed96-4d69-bfab-9df6a07f622a>\",\"Content-Length\":\"17179\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3dc69ebb-cb10-49e4-b699-98e9e88b9286>\",\"WARC-Concurrent-To\":\"<urn:uuid:08082dc4-3960-4319-9afd-4c9e2fd9efb9>\",\"WARC-IP-Address\":\"35.214.9.253\",\"WARC-Target-URI\":\"http://pycreeper.lenkaspace.net/_modules/examples/brokenLinePlots.html\",\"WARC-Payload-Digest\":\"sha1:HQAPBJ6TXYYDG3NRJM7564AHOT5HHWXQ\",\"WARC-Block-Digest\":\"sha1:WAWCYTV4DSCDV73W654QRSTEL2HZAV7E\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662595559.80_warc_CC-MAIN-20220526004200-20220526034200-00570.warc.gz\"}"}