linear_target.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import numpy as np
  2. from modules.graphs.style_settings import DEFAULT_STYLE_SETTINGS
  3. class LinearTarget:
  4. def __init__(self, fig, subplot_spec, max_dist, step, threshold, color_settings=DEFAULT_STYLE_SETTINGS):
  5. self._plt = fig.add_subplot(subplot_spec)
  6. self._max_dist = max_dist
  7. self._step = step
  8. self._threshold = threshold
  9. self._color_settings = color_settings
  10. def plot(self, z, resize_by_data=True):
  11. if resize_by_data and len(z) > 0:
  12. actual_max_dist = max(np.max(np.abs(z)), self._max_dist)
  13. else:
  14. actual_max_dist = self._max_dist
  15. x = np.zeros(z.size)
  16. self._show_scale(actual_max_dist + self._step)
  17. self._show_ticks(actual_max_dist + self._step)
  18. self._plt.scatter(
  19. x,z,
  20. c=self._color_settings.color_data_fill,
  21. s=self._color_settings.size_data_point,
  22. edgecolors=self._color_settings.color_data_border,
  23. linewidths=self._color_settings.size_data_border,
  24. zorder=3,
  25. alpha=self._color_settings.alpha_data
  26. )
  27. # Vyznačenie nuly a úprava osí
  28. self._plt.axhline(0, color=self._color_settings.color_contour, linestyle='-', alpha=1.0, linewidth=1.5, zorder=2)
  29. # self._plt.set_xlim(-0.15, 0.15)
  30. self._plt.set_xticks([])
  31. self._plt.set_ylim(-actual_max_dist, actual_max_dist)
  32. #self._plt.set_ylabel("Odchýlka hĺbky Z (mm)", fontweight='bold', color=self._color_settings.color_contour)
  33. #self._plt.set_title("Jednoosová hĺbka", fontsize=11, fontweight='bold', color=self._color_settings.color_contour, pad=10)
  34. # Mriežka a rámčeky
  35. self._plt.grid(True, axis='y', linestyle='-', color=self._color_settings.color_contour, alpha=0.8)
  36. for spine in self._plt.spines.values():
  37. spine.set_edgecolor(self._color_settings.color_contour)
  38. spine.set_alpha(self._color_settings.alpha_contour)
  39. self._plt.tick_params(colors=self._color_settings.color_contour, grid_color=self._color_settings.color_contour)
  40. def _show_scale(self, y_limit_val):
  41. for val in range(0, int(y_limit_val) + self._step, self._step):
  42. idx = val // self._step
  43. # show positive
  44. if val + self._step <= self._threshold:
  45. c_pos = self._color_settings.color_ok_dark if idx % 2 == 0 else self._color_settings.color_ok_light
  46. else:
  47. c_pos = self._color_settings.color_err_dark if idx % 2 == 0 else self._color_settings.color_err_light
  48. self._plt.axhspan(val, val + self._step, color=c_pos, alpha=self._color_settings.alpha_scale, zorder=0)
  49. # Záporný smer Z
  50. if val + self._step <= self._threshold:
  51. c_neg = self._color_settings.color_ok_dark if idx % 2 == 0 else self._color_settings.color_ok_light
  52. else:
  53. c_neg = self._color_settings.color_err_dark if idx % 2 == 0 else self._color_settings.color_err_light
  54. self._plt.axhspan(-val - self._step, -val, color=c_neg, alpha=self._color_settings.alpha_scale, zorder=0)
  55. def _show_ticks(self, max_dist):
  56. self._plt.set_xticks([])
  57. self._plt.set_xticklabels([])
  58. self._plt.set_yticks(np.arange(-max_dist, max_dist+1, self._step))
  59. self._plt.grid(True, linestyle='-', color=self._color_settings.color_contour, alpha=self._color_settings.alpha_contour)
  60. #self._plt.spines['polar'].set_color(self._color_settings.color_contour)
  61. #self._plt.spines['polar'].set_alpha(self._color_settings.alpha_contour)