Skip to content
Snippets Groups Projects
Commit 318d1e6a authored by Lan Dam's avatar Lan Dam
Browse files

create function get_colors_sizes_for_abs_y_from_value_colors() to be easier in testing

parent 4a39ffe2
No related branches found
No related tags found
1 merge request!175correct the way to identify colors for mass pos
......@@ -5,6 +5,9 @@ from sohstationviewer.controller.util import get_val
from sohstationviewer.controller.plotting_data import get_masspos_value_colors
from sohstationviewer.view.util.color import clr
from sohstationviewer.view.plotting.plotting_widget.plotting_helper import (
get_colors_for_abs_y_from_value_colors
)
from sohstationviewer.conf import constants
......@@ -377,24 +380,14 @@ class Plotting:
self.plotting_axes.set_axes_info(
ax, [total_x], chan_db_info=chan_db_info, y_list=y_list)
for x, y in zip(x_list, y_list):
# plot to have artist pl.Line2D to get pick
ax.myPlot = ax.plot(x, y,
linestyle='-', linewidth=0.7,
color=self.parent.display_color['sub_basic'],
picker=True, pickradius=3,
zorder=constants.Z_ORDER['LINE'])[0]
colors = [None] * len(y)
sizes = [1.5] * len(y)
for i in range(len(y)):
count = -1
for v, c in value_colors:
count += 1
if count <= len(value_colors) - 2:
if abs(y[i]) <= v:
colors[i] = clr[c]
break
else:
# The last value color
colors[i] = clr[c]
colors, sizes = get_colors_for_abs_y_from_value_colors(
y, value_colors)
ax.scatter(x, y, marker='s', c=colors, s=sizes,
zorder=constants.Z_ORDER['DOT'])
ax.x_list = x_list
......
from typing import List, Tuple
from sohstationviewer.view.util.color import clr
def get_colors_sizes_for_abs_y_from_value_colors(
y: List[float],
value_colors: List[Tuple[float, str]]) -> \
Tuple[List[str], List[float]]:
"""
Map each abs(value) in y with the value in value_colors to get the colors
for the indexes corresponding to the y's items.
Sizes is currently similar for all items
:param y: list of data values
:param value_colors: list of color with indexes corresponding to y's items
:return colors: list of colors of markers corresponding to y
:return sizes: list of sizes of markers corresponding to y
"""
colors = [None] * len(y)
sizes = [1.5] * len(y)
for i in range(len(y)):
count = -1
for v, c in value_colors:
count += 1
if count <= len(value_colors) - 2:
if abs(y[i]) <= v:
colors[i] = clr[c]
break
else:
# The last value color
colors[i] = clr[c]
return colors, sizes
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment