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

correct the way to identify colors for mass pos

parent a2850f6c
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_sizes_for_abs_y_from_value_colors
)
from sohstationviewer.conf import constants
......@@ -378,26 +381,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 = 0
prev_v = 0
for v, c in value_colors:
if count < (len(value_colors) - 1):
if prev_v < abs(y[i]) <= v:
colors[i] = clr[c]
break
else:
colors[i] = clr[c]
break
prev_v = v
count += 1
colors, sizes = get_colors_sizes_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
from unittest import TestCase
from sohstationviewer.view.plotting.plotting_widget.plotting_helper import (
get_colors_sizes_for_abs_y_from_value_colors
)
from sohstationviewer.view.util.color import clr
class TestGetColorsSizesForAbsYFromValueColors(TestCase):
def test_get_colors_sizes_for_abs_y_from_value_colors(self):
y = [0, 0.5, 1., 2., 3., 4., 5., 7., 7.1,
-0, -0.5, -1., -2., -3., -4., -5., -7., -7.1]
value_colors = [(0.5, 'C'), (2.0, 'G'), (4.0, 'Y'),
(7.0, 'R'), (7.0, 'M')]
colors, sizes = get_colors_sizes_for_abs_y_from_value_colors(
y, value_colors)
self.assertEqual(
colors,
[clr['C'], clr['C'], clr['G'], clr['G'], clr['Y'], clr['Y'],
clr['R'], clr['R'], clr['M'],
clr['C'], clr['C'], clr['G'], clr['G'], clr['Y'], clr['Y'],
clr['R'], clr['R'], clr['M']
]
)
self.assertEqual(sizes, [1.5] * len(y))
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