def test_calculate_image_mode_default(self): """ default should be hierarchic """ expection = [ 0.53202614, 0.16862745, 0.01568627, 0.93071895, 0.38562092, 0.06666667, 0.93071895, 0.38562092, 0.06666667, 1., 1., 1., 0.93071895, 0.38562092, 0.06666667, 0.89451024, 0.58912264, 0.36889634, 0.89451024, 0.58912264, 0.36889634, 1., 1., 1., 0.93071895, 0.38562092, 0.06666667, 0.52720176, 0.57970919, 0.39866916, 0.62858396, 0.60270744, 0.64328974, 1., 1., 1., 0.99215686, 0.70326797, 0.45359477, 0.53919441, 0.71270852, 0.48192737, 0.78778644, 0.82220669, 0.6597027, 1., 1., 1., 1., 1., 1., 0., 0.32418301, 0.16601307, 0., 0.32418301, 0.16601307, 1., 1., 1. ] z_list = [[[0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.3, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1]], [[0.4, 0.3, 0.3, 0.1], [0.3, 0.3, 0.3, 0.1], [0.3, 0.3, 0.2, 0.1], [0.2, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1]], [[0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.2, 0.1], [0.1, 0.4, 0.4, 0.1]]] z_min, z_max, = 0.1, 0.4 z_sum = [[0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.3, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1], [0.4, 0.3, 0.3, 0.1], [0.3, 0.3, 0.3, 0.1], [0.3, 0.3, 0.2, 0.1], [0.2, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.2, 0.1], [0.1, 0.4, 0.4, 0.1]] colorschemes = color_schemes.get_colorbrewer_schemes() result, _ = picture_contours.calculate_image(z_list, z_min, z_max, z_sum, colorschemes, method="normal", use_c_implementation=True, mode="default") np.testing.assert_almost_equal(expection, result.flatten())
def test_generate_crosses_colors(self): dist_one_colors = [[0.77647059, 0.85882353, 0.9372549, 1.], [0.12941176, 0.44313725, 0.70980392, 1.], [.12941176, 0.44313725, 0.70980392, 1.], [0.77647059, 0.85882353, 0.9372549, 1.]] dist_two_colors = [[0.99607843, 0.92428677, 0.85887397, 1.], [0.99215686, 0.77615063, 0.57159781, 1.], [0.99215686, 0.77615063, 0.57159781, 1.], [0.99607843, 0.92428677, 0.85887397, 1.]] dist_1 = Gaussian(means=[1, 0], cov_matrix=[[3, 2], [2, 3]], x_min=self.x_min, x_max=self.x_max, y_min=self.y_min, y_max=self.y_max, size=self.size, weight=self.weight) dist_2 = Gaussian(means=[0, 1], cov_matrix=[[6, 2], [2, 6]], x_min=self.x_min, x_max=self.x_max, y_min=self.y_min, y_max=self.y_max, size=self.size, weight=self.weight) distributions = [dist_1, dist_2] # unpleasant.... limits = helper.get_limits(distributions) z_list = helper.generate_distribution_grids(distributions, limits=limits) z_min, z_max, z_sum = helper.generate_weights(z_list) colorschemes = color_schemes.get_colorbrewer_schemes() crosses = picture_cross.generate_crosses(distributions, z_list, z_min, z_max, colorschemes, method="normal", num_of_levels=1) np.testing.assert_almost_equal(dist_one_colors, crosses[0][2]) np.testing.assert_almost_equal(dist_one_colors, crosses[0][3]) np.testing.assert_almost_equal(dist_two_colors, crosses[1][2]) np.testing.assert_almost_equal(dist_two_colors, crosses[1][3])
def generate_random_points(distributions, colorschemes=None, z_list=None, z_min=None, z_max=None, xlim=None, ylim=None, *args, **kwargs): limits = helper.get_limits(distributions, xlim, ylim) if z_list is None: z_list = helper.generate_distribution_grids(distributions, limits=limits) if z_min is None: z_min, z_max, z_sum = helper.generate_weights(z_list) if colorschemes is None: colorschemes = color_schemes.get_colorbrewer_schemes() return __generate_random_points(distributions, z_list, z_min, z_max, colorschemes[:len(distributions)], *args, **kwargs)
def test_calculate_image_single(self): expection = [[0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.3, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1]] z_list = [[[0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.3, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1]]] z_min, z_max, = 0.1, 0.3 z_sum = [[0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.3, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1]] colorschemes = color_schemes.get_colorbrewer_schemes() _, z_new = picture_contours.calculate_image(z_list, z_min, z_max, z_sum, colorschemes, method="normal") np.testing.assert_almost_equal(expection, z_new)
def test_generate_crosses_iso_lines(self): dist_one_iso_lines = [0.25, 0.75, 0.75, 0.25] dist_two_iso_lines = [ 0.09889134000871382, 0.2966740200253193, 0.2966740200253193, 0.09889134000871382 ] dist_1 = Gaussian(means=[1, 0], cov_matrix=[[3, 2], [2, 3]], x_min=self.x_min, x_max=self.x_max, y_min=self.y_min, y_max=self.y_max, size=self.size, weight=self.weight) dist_2 = Gaussian(means=[0, 1], cov_matrix=[[6, 2], [2, 6]], x_min=self.x_min, x_max=self.x_max, y_min=self.y_min, y_max=self.y_max, size=self.size, weight=self.weight) distributions = [dist_1, dist_2] # unpleasant.... limits = helper.get_limits(distributions) z_list = helper.generate_distribution_grids(distributions, limits=limits) z_min, z_max, z_sum = helper.generate_weights(z_list) colorschemes = color_schemes.get_colorbrewer_schemes() crosses = picture_cross.generate_crosses(distributions, z_list, z_min, z_max, colorschemes, method="normal", num_of_levels=1) np.testing.assert_almost_equal(dist_one_iso_lines, crosses[0][4]) np.testing.assert_almost_equal(dist_two_iso_lines, crosses[1][4])
def test_calculate_image_z_values_mode_default(self): """ default should be hierarchic """ expection = [ 0.4, 0.3, 0.3, 0.1, 0.3, 0.26, 0.26, 0.1, 0.3, 0.3, 0.26, 0.1, 0.2, 0.26, 0.2, 0.1, 0.1, 0.4, 0.4, 0.1 ] z_list = [[[0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.3, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1]], [[0.4, 0.3, 0.3, 0.1], [0.3, 0.3, 0.3, 0.1], [0.3, 0.3, 0.2, 0.1], [0.2, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1]], [[0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.2, 0.1], [0.1, 0.4, 0.4, 0.1]]] z_min, z_max, = 0.1, 0.4 z_sum = [[0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.3, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1], [0.4, 0.3, 0.3, 0.1], [0.3, 0.3, 0.3, 0.1], [0.3, 0.3, 0.2, 0.1], [0.2, 0.2, 0.2, 0.1], [0.1, 0.1, 0.1, 0.1], [0.1, 0.1, 0.1, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.2, 0.1], [0.1, 0.4, 0.4, 0.1]] colorschemes = color_schemes.get_colorbrewer_schemes() _, z_new = picture_contours.calculate_image(z_list, z_min, z_max, z_sum, colorschemes, method="normal", use_c_implementation=True, mode="default") np.testing.assert_almost_equal(expection, z_new.flatten())
def test_calculate_image_constructed(self): expection = [ 1., 1., 1., 0.59361887, 0.39521946, 0.34250093, 0.48627451, 0.71895425, 0.85359477, 1., 1., 1., 1., 1., 1., 0.59361887, 0.39521946, 0.34250093, 0.48627451, 0.71895425, 0.85359477, 1., 1., 1., 1., 1., 1., 0.59361887, 0.39521946, 0.34250093, 0.48627451, 0.71895425, 0.85359477, 1., 1., 1., 1., 1., 1., 0.59361887, 0.39521946, 0.34250093, 0.48627451, 0.71895425, 0.85359477, 1., 1., 1., 1., 1., 1., 0.59361887, 0.39521946, 0.34250093, 0.48627451, 0.71895425, 0.85359477, 1., 1., 1. ] z_list = [[[0.1, 0.2, 0.2, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.2, 0.2, 0.1]], [[0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.1, 0.1]]] z_min, z_max, z_sum = 0.1, 0.3, [[0.1, 0.2, 0.2, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.2, 0.2, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.1, 0.1], [0.1, 0.3, 0.1, 0.1]] colorschemes = color_schemes.get_colorbrewer_schemes() result, _ = picture_contours.calculate_image(z_list, z_min, z_max, z_sum, colorschemes, method="normal") np.testing.assert_almost_equal(expection, result.flatten())
def input_image(ax, distribution, z_sum=None, num_of_pies_x=10, num_of_pies_y=0, angle=0, set_limit=False, iso_level=8, level_to_cut=1, contour_method="equal_density", colorschemes=color_schemes.get_colorbrewer_schemes(), modus="light", borders=None, scale=1., xlim=None, ylim=None): limits = helper.get_limits(distribution, xlim, ylim) if borders is None: if modus == "size": borders = [0.1, 1] else: borders = [.2, .9] if set_limit: ax.set_xlim([limits.x_min, limits.x_max]) ax.set_ylim([limits.y_min, limits.y_max]) if num_of_pies_y == 0: num_of_pies_y = get_distance_ratio(num_of_pies_x, limits) container, distances = container_size(num_of_pies_x, num_of_pies_y, limits) if z_sum is None: z_list = helper.generate_distribution_grids(distribution, limits) z_min, z_max, z_sum = helper.generate_weights(z_list) else: z_min = np.min(z_sum) z_max = np.max(z_sum) if iso_level: if 0 < level_to_cut <= iso_level: barrier = iso_lines.get_iso_levels(z_sum, contour_method, iso_level)[level_to_cut - 1] else: if level_to_cut > 0: logger.warning( "Point to cut[{}] is not in iso-level[{}]. Using pie-charts without point to cut" .format(level_to_cut, iso_level)) barrier = None else: barrier = None lw_borders = [ iso_lines.get_iso_levels( i.get_density_grid(i.size, limits.x_min, limits.x_max, limits.y_min, limits.y_max)[2])[0] for i in distribution ] for k in container[0][0]: for l in container[1]: middle_point = k, l[0] input_values = [] for j in range(len(distribution)): input_values.append(distribution[j].get_density(middle_point)) if not barrier: generate_pie(ax, middle_point, input_values, angle, distances, z_min, z_max, borders, modus, colorschemes, scale, lw_borders) elif sum(input_values) > barrier: generate_pie(ax, middle_point, input_values, angle, distances, z_min, z_max, borders, modus, colorschemes, scale, lw_borders)
import numpy as np from matplotlib.patches import Wedge from contour_visualization import helper, color_schemes, iso_lines import logging logger = logging.getLogger(__name__) colorschemes = color_schemes.get_colorbrewer_schemes() color_codes = [color_schemes.get_main_color(i)[-4] for i in colorschemes] def sort_ratios(sorting_list, sorted_list): """ sorts both lists with with the keys from the first list :param sorting_list: list which is used to sort :param sorted_list: list which is sorted by first list :return: both list sorted by first list """ if len(sorting_list) != len(sorted_list): raise ValueError("Length of list not equale {} != {}".format( len(sorting_list), len(sorted_list))) return zip(*sorted(zip(sorting_list, sorted_list[:len(sorting_list)]))) def draw_pie( ax, ratios, center,
def input_image( ax, distributions, z_list=None, z_min=None, z_max=None, z_sum=None, colorschemes=None, method="equal_density", num_of_levels=8, color_space="lab", use_c_implementation=False, mode="hierarchic", blending_operator=hierarchic_blending_operator.porter_duff_source_over, borders=None, min_gauss=False, lower_border=None, lower_border_to_cut=0, xlim=None, ylim=None): """ inputs the contours of distributions into an matplotlib axis object :param ax: matplotlib axis :param distributions: list of :class:`contour_visualization.Distribution.Distribution` :param z_list: list of densities each one with the same shape [density_1, ... , density_n] :param z_min: minimal density occurring in the z_list min([density_1, ... , density_n]) :param z_max: maximal density occurring in the z_list max([density_1, ... , density_n]) :param colorschemes: colorschemes to use for each density-grid :param method: method with which the distance between contour-lines is chosen :param num_of_levels: number of contour-lines to use :param color_space: colorspace to merge the images in "rgb" or "lab" :param use_c_implementation: run the merging process with the c-implementation :param mode: sets the mode to use. Defaults is hierarchic and defaults to hierarchic :param blending_operator: operator with which the pictures are merged :param borders: min and max color from colorspace which is used from 0. to 1. """ limits = helper.get_limits(distributions, xlim, ylim) if z_list is None: z_list = helper.generate_distribution_grids(distributions, limits=limits) if z_min is None: z_min, z_max, z_sum = helper.generate_weights(z_list) if colorschemes is None: colorschemes = color_schemes.get_colorbrewer_schemes() img, alpha = calculate_image(z_list, z_min, z_max, z_sum, colorschemes, method, num_of_levels, color_space, use_c_implementation, mode, blending_operator, borders, min_gauss=min_gauss, lower_border=lower_border, lower_border_to_cut=lower_border_to_cut) extent = [limits.x_min, limits.x_max, limits.y_min, limits.y_max] ax.imshow(img, extent=extent, origin='lower')
def test_calculate_image_real_small(self): expection = [ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0.99618958, 0.93030094, 0.87203314, 0.47583421, 0.3521213, 0.47779367, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0.99607843, 0.91240782, 0.83172208, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1. ] z_list = [[[ 7.35424658e-12, 1.79952481e-09, 1.34697725e-13, 3.08422074e-24, 2.16029678e-41 ], [ 1.21251028e-11, 6.53506479e-05, 1.07745003e-04, 5.43409406e-11, 8.38378119e-24 ], [ 6.11526724e-18, 7.25980122e-07, 2.63643330e-02, 2.92881285e-04, 9.95289044e-13 ], [ 9.43470281e-31, 2.46707488e-15, 1.97341857e-06, 4.82879604e-04, 3.61444219e-08 ], [ 4.45270353e-50, 2.56461812e-30, 4.51860527e-17, 2.43539199e-10, 4.01528258e-10 ]], [[ 1.36757424e-08, 4.97389608e-07, 1.66604650e-07, 5.13951507e-10, 1.46016450e-14 ], [ 1.73606032e-06, 3.01228273e-04, 4.81361410e-04, 7.08420997e-06, 9.60187826e-10 ], [ 2.02966014e-06, 1.68011641e-03, 1.28085521e-02, 8.99301508e-04, 5.81507366e-07 ], [ 2.18537742e-08, 8.63033452e-05, 3.13887068e-03, 1.05138998e-03, 3.24338767e-06 ], [ 2.16707627e-12, 4.08282253e-08, 7.08420997e-06, 1.13205353e-05, 1.66604650e-07 ]]] z_min, z_max, = 4.452703529915074e-50, 0.026364333048110374 z_sum = [[ 1.36830967e-08, 4.99189133e-07, 1.66604784e-07, 5.13951507e-10, 1.46016450e-14 ], [ 1.73607244e-06, 3.66578921e-04, 5.89106413e-04, 7.08426431e-06, 9.60187826e-10 ], [ 2.02966014e-06, 1.68084239e-03, 3.91728851e-02, 1.19218279e-03, 5.81508361e-07 ], [ 2.18537742e-08, 8.63033452e-05, 3.14084410e-03, 1.53426959e-03, 3.27953209e-06 ], [ 2.16707627e-12, 4.08282253e-08, 7.08420997e-06, 1.13207788e-05, 1.67006178e-07 ]] colorschemes = color_schemes.get_colorbrewer_schemes() result, _ = picture_contours.calculate_image(z_list, z_min, z_max, z_sum, colorschemes, method="normal") np.testing.assert_almost_equal(expection, result.flatten())
def plot_image( ax, distributions, contour_lines=False, contour_line_colorscheme=color_schemes. get_background_colorbrewer_scheme(), contour_lines_method="equal_density", contour_lines_weighted=True, contour_line_level=5, contour_line_borders=None, linewidth=2, contours=False, contour_colorscheme=color_schemes.get_colorbrewer_schemes(), contour_method="equal_density", contour_lvl=8, color_space="lab", use_c_implementation=True, contour_mode="hierarchic", blending_operator=hierarchic_blending_operator.porter_duff_source_over, contour_min_gauss=False, contour_lower_border_lvl=None, contour_lower_border_to_cut=0, contour_borders=None, crosses=False, cross_colorscheme=color_schemes.get_colorbrewer_schemes(), cross_width="5%", cross_same_broad=True, cross_length_multiplier=2. * np.sqrt(2.), cross_borders=None, cross_fill=True, cross_line_width=0., cross_blending_operator=hierarchic_blending_operator. porter_duff_source_over, cross_mode="hierarchic", pie_charts=False, pie_num=25, pie_angle=90, pie_chart_colors=None, pie_chart_modus="light", pie_chart_scale=1., pie_chart_borders=None, pie_chart_iso_level=40, pie_chart_level_to_cut=1, pie_chart_contour_method="equal_density", scatter_points=False, schatter_points_colors=None, scatter_points_num=1000, legend=False, legend_lw=2, legend_colors=None, legend_names=None, xlim=None, ylim=None, title="", xlabel="", ylabel="", *args, **kwargs): """ Plots an image at a given axe, can plot contour, contour-lines, crosses and pie-charts :param ax: axis to plot on :param distributions: list of distributions to plot [distribution_1, ... distribution_n] :param contour_lines: :param contour_line_colorscheme: :param contour_lines_method: :param contour_lines_weighted: :param contour_line_level: :param contour_line_borders: :param linewidth: :param contours: :param contour_colorscheme: :param contour_method: method with which the colored areas are calculated :param contour_lvl: :param color_space: :param use_c_implementation: :param contour_mode: sets the mode to use. Defaults is hierarchic and defaults to hierarchic :param blending_operator: blendingoperator to use. Only works for blending in python :param contour_min_gauss: if min of min gauss is used when True else from z_sum :param contour_lower_border_to_cut: defines the global lower border at which to cut the particular each image :param contour_lower_border_lvl: def at which level the iso-border gets cut :param contour_borders: :param crosses: :param cross_colorscheme: :param cross_width: :param cross_same_broad: if True calculates the broad of the crosses depending by the smaller cross :param cross_length_multiplier: is multiplied with the lenght to create bigger or smaller crosses :param cross_borders: :param cross_fill: if cross is filled with color or not :param cross_blending_operator: blending operotor for cross-intersections :param pie_charts: :param pie_num: :param pie_angle: where the pie-chart begins 0 is horizontal beginning on the right 90 beginns at the top :param pie_chart_colors: Colorscheme to use. Defaults is colorbrewer :param pie_chart_modus: "light" or "size" if "size" global density is coded with size elif "light" through the colorscheme :param pie_chart_scale: when light selected sets the size of the pies :param pie_chart_borders: [0.,1.] range of ether size or color lightness of the pies :param pie_chart_iso_level: :param pie_chart_level_to_cut: :param pie_chart_contour_method: :param legend: if a legend should be plotted or not :param legend_lw: :param legend_colors: plots colors as lines to legend if not chosen defaults to contour-colors :param legend_names: if set uses names instead of numbers :param title: title specified if not given non is plotted :param xlabel: :param ylabel: :return: """ if contours or contour_lines or pie_charts or crosses or scatter_points: limits = helper.get_limits(distributions, xlim, ylim) z_list = helper.generate_distribution_grids(distributions, limits=limits) z_min, z_max, z_sum = helper.generate_weights(z_list) if not contours: if isinstance(ax, type(plt)): ax.xlim((limits.x_min, limits.x_max)) ax.ylim((limits.y_min, limits.y_max)) else: ax.set_xlim((limits.x_min, limits.x_max), emit=False) ax.set_ylim((limits.y_min, limits.y_max), emit=False) if title: if isinstance(ax, type(plt)): ax.title(title) else: ax.set_title(title) if legend: if not legend_colors: legend_colors = color_schemes.get_representiv_colors( _evaluate_colors([ _evaluate_colors( [[ contour_line_colorscheme, ] if isinstance(contour_line_colorscheme, dict) else contour_line_colorscheme, [ contour_colorscheme, ] if isinstance(contour_colorscheme, dict) else contour_colorscheme, pie_chart_colors], len(distributions)), pie_chart_colors ], len(distributions)))[:len(distributions)] _generate_legend(ax, legend_colors, legend_names, legend_lw=legend_lw) if contours: if isinstance(contour_colorscheme, dict): picture_contours.input_image( ax, [distributions[0]], [z_sum], np.min(z_sum), np.max(z_sum), z_sum, [contour_colorscheme], contour_method, contour_lvl, color_space, use_c_implementation, contour_mode, blending_operator=blending_operator, borders=contour_borders, min_gauss=contour_min_gauss, lower_border=contour_lower_border_lvl, lower_border_to_cut=contour_lower_border_to_cut, xlim=xlim, ylim=ylim) else: picture_contours.input_image( ax, distributions, z_list, z_min, z_max, z_sum, contour_colorscheme, contour_method, contour_lvl, color_space, use_c_implementation, contour_mode, blending_operator=blending_operator, borders=contour_borders, min_gauss=contour_min_gauss, lower_border=contour_lower_border_lvl, lower_border_to_cut=contour_lower_border_to_cut, xlim=xlim, ylim=ylim) if crosses: picture_cross.input_crosses( ax, distributions, z_list, z_min, z_max, cross_colorscheme, cross_width, cross_same_broad, cross_length_multiplier, cross_borders, linewidth=cross_line_width, cross_fill=cross_fill, blending_operator=cross_blending_operator, mode=cross_mode, color_space=color_space, *args, **kwargs) if contour_lines: if isinstance(contour_line_colorscheme, dict): picture_contour_lines.generate_contour_lines( ax, z_sum, limits, contour_line_colorscheme, contour_lines_method, contour_lines_weighted, contour_line_level, contour_line_borders, linewidth) else: for z_values, scheme in zip(z_list, contour_line_colorscheme): picture_contour_lines.generate_contour_lines( ax, z_values, limits, scheme, contour_lines_method, contour_lines_weighted, contour_line_level, contour_line_borders, linewidth) if pie_charts: if pie_chart_colors is None: pie_chart_colors = contour_colorscheme pie_chart_vis.input_image(ax, distributions, z_sum, pie_num, angle=pie_angle, colorschemes=pie_chart_colors, modus=pie_chart_modus, borders=pie_chart_borders, iso_level=pie_chart_iso_level, level_to_cut=pie_chart_level_to_cut, contour_method=pie_chart_contour_method, scale=pie_chart_scale, set_limit=False, xlim=xlim, ylim=ylim) if scatter_points: logger.debug("Plotting scatter points") if schatter_points_colors is None: schatter_points_colors = contour_colorscheme draw_random_points.input_points( ax, distributions, colorschemes=schatter_points_colors, num=scatter_points_num, *args, **kwargs) if isinstance(ax, type(plt)): ax.xlim((limits.x_min, limits.x_max)) ax.ylim((limits.y_min, limits.y_max)) else: ax.set_xlim((limits.x_min, limits.x_max), emit=False) ax.set_ylim((limits.y_min, limits.y_max), emit=False) # # to avoid a stretched y-axis if isinstance(ax, type(plt)): pass # ax.aspect('equal', adjustable='box') else: ax.set_aspect('equal', adjustable='box') logger.debug("Axis-limits: {}".format(limits)) if xlabel: if isinstance(ax, type(plt)): ax.xlabel(xlabel) else: ax.set_xlabel(xlabel) if ylabel: if isinstance(ax, type(plt)): ax.ylabel(ylabel) else: ax.set_ylabel(ylabel)
def test_generate_crosses_crosses(self): dist_one_first_line = [((1., -4.), (5., 4.440892098500626e-16)), ((-0.181818, -2.818181), (3.818181, 1.181818)), ((-1., -2.), (3., 2.)), ((-1.818181, -1.181818), (2.181818, 2.818181)), ((-3., -4.440892098500626e-16), (1., 4.))] dist_one_second_line = [((-1.4721359549995792, -6.47213595499958), (-5.47213595499958, -2.472135954999579)), ((1.1162821280456323, -3.8837178719543686), (-2.8837178719543686, 0.11628212804563232)), ((3.0000000000000004, -2.0000000000000004), (-1.0000000000000004, 2.0000000000000004)), ((4.883717871954369, -0.11628212804563187), (0.8837178719543681, 3.883717871954369)), ((7.47213595499958, 2.472135954999579), (3.472135954999579, 6.47213595499958))] dist_two_first_line = [ ((0.0, -7.000000000000002), (8.000000000000002, 1.0)), ((-2.363636363636364, -4.636363636363638), (5.636363636363638, 3.363636363636364)), ((-4.000000000000001, -3.000000000000001), (4.000000000000001, 5.000000000000001)), ((-5.636363636363638, -1.3636363636363642), (2.363636363636364, 6.636363636363638)), ((-8.000000000000002, 1.0), (0.0, 9.000000000000002)) ] dist_two_second_line = [((-1.6568542494923806, -8.656854249492383), (-9.656854249492383, -0.6568542494923806)), ((1.6172644221835126, -5.382735577816489), (-6.382735577816489, 2.6172644221835126)), ((4.000000000000001, -3.000000000000001), (-4.000000000000001, 5.000000000000001)), ((6.382735577816488, -0.6172644221835135), (-1.6172644221835135, 7.382735577816488)), ((9.656854249492383, 2.6568542494923806), (1.6568542494923806, 10.656854249492383))] dist_1 = Gaussian(means=[1, 0], cov_matrix=[[3, 2], [2, 3]], x_min=self.x_min, x_max=self.x_max, y_min=self.y_min, y_max=self.y_max, size=self.size, weight=self.weight) dist_2 = Gaussian(means=[0, 1], cov_matrix=[[6, 2], [2, 6]], x_min=self.x_min, x_max=self.x_max, y_min=self.y_min, y_max=self.y_max, size=self.size, weight=self.weight) distributions = [dist_1, dist_2] # unpleasant.... limits = helper.get_limits(distributions) z_list = helper.generate_distribution_grids(distributions, limits=limits) z_min, z_max, z_sum = helper.generate_weights(z_list) colorschemes = color_schemes.get_colorbrewer_schemes() crosses = picture_cross.generate_crosses(distributions, z_list, z_min, z_max, colorschemes, method="normal", num_of_levels=1) np.testing.assert_almost_equal(dist_one_first_line, crosses[0][0], decimal=5) np.testing.assert_almost_equal(dist_one_second_line, crosses[0][1], decimal=5) np.testing.assert_almost_equal(dist_two_first_line, crosses[1][0], decimal=5) np.testing.assert_almost_equal(dist_two_second_line, crosses[1][1], decimal=5)