wolfhece 2.2.2__py3-none-any.whl → 2.2.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wolfhece/apps/version.py CHANGED
@@ -5,7 +5,7 @@ class WolfVersion():
5
5
 
6
6
  self.major = 2
7
7
  self.minor = 2
8
- self.patch = 2
8
+ self.patch = 3
9
9
 
10
10
  def __str__(self):
11
11
 
@@ -0,0 +1 @@
1
+ from . import _add_path
@@ -0,0 +1,135 @@
1
+ import matplotlib.pyplot as plt
2
+ import numpy as np
3
+ from matplotlib.colors import LinearSegmentedColormap
4
+
5
+
6
+
7
+ class Semi_Circle_Gauge():
8
+
9
+ def __init__(self):
10
+ # Create a polar plot for the speedometer background
11
+ self.fig, self.ax = plt.subplots(figsize=(6, 3), subplot_kw={'projection': 'polar'})
12
+ self.ax.set_theta_zero_location('W')
13
+ self.ax.set_theta_direction(-1)
14
+
15
+ def plot_background(self):
16
+ # Define the ranges for red, yellow, and green
17
+ theta = np.linspace(0, np.pi, 500)
18
+ # Create metallic gradient for green with highlights for a modern effect
19
+ green_cmap = LinearSegmentedColormap.from_list(
20
+ "metallic_green", ["#003300", "#00FF00", "#66FF66", "#00FF00", "#003300"]
21
+ )
22
+ green_colors = green_cmap(np.linspace(0, 1, 500))
23
+ self.ax.fill_between(theta, 0, 1, where=(theta <= np.pi/3), color=None, alpha=0.7, facecolor=green_colors)
24
+ # green_cmap = LinearSegmentedColormap.from_list("metallic_green", ["#006400", "#00FF00", "#006400"])
25
+ # green_colors = green_cmap(np.linspace(0, 1, 500))
26
+ # ax.fill_between(theta, 0, 1, where=(theta <= np.pi/3), color=None, alpha=0.7, facecolor=green_colors)
27
+
28
+ # Create metallic gradient for yellow
29
+ yellow_cmap = LinearSegmentedColormap.from_list("metallic_yellow", ["#FFD700", "#FFFF00", "#FFD700"])
30
+ yellow_colors = yellow_cmap(np.linspace(0, 1, 500))
31
+ self.ax.fill_between(theta, 0, 1, where=((theta > np.pi/3) & (theta <= 2*np.pi/3)), color=None, alpha=0.7, facecolor=yellow_colors)
32
+
33
+ # Create metallic gradient for red
34
+ red_cmap = LinearSegmentedColormap.from_list("metallic_red", ["#8B0000", "#FF0000", "#8B0000"])
35
+ red_colors = red_cmap(np.linspace(0, 1, 500))
36
+ self.ax.fill_between(theta, 0, 1, where=(theta > 2*np.pi/3), color=None, alpha=0.7, facecolor=red_colors)
37
+
38
+ # Remove polar grid and labels for a clean look
39
+ self.ax.grid(False)
40
+ self.ax.set_yticks([])
41
+ self.ax.set_xticks([])
42
+
43
+ self.ax.set_ylim(0, 1)
44
+ self.ax.set_xlim(0, np.pi)
45
+
46
+ def plot_needle(self, value, color='black'):
47
+ # Add a needle to indicate a specific value
48
+ width = 0.1 # Needle width
49
+ self.ax.fill([value, value-width, value, value+width, value],
50
+ [0, .25, .9, .25, 0], color='black', linewidth=2, zorder=5)
51
+ self.ax.plot([value, value+width*.9, value],
52
+ [.9, .25, 0], color='grey', linewidth=2, zorder=6)
53
+ self.ax.plot([value, value+width, value],
54
+ [.9, .25, 0], color='white', linewidth=1, zorder=6)
55
+ # Plot a black semi-circle at the origin
56
+ semi_circle = plt.Circle((0, 0), 0.1, transform=self.ax.transData._b, color='black', zorder=7)
57
+ self.ax.add_artist(semi_circle)
58
+
59
+ def plot_text(self, text, value):
60
+ # Add text to the speedometer
61
+ # The text is above the speedometer in the center
62
+ # The value is the angle of the needle
63
+ self.ax.text(np.pi/2., 1.15, text, fontsize=12, ha='center', va='center', color='black')
64
+
65
+ class Rectangular_Gauge():
66
+
67
+ def __init__(self, horizontal_or_vertical='vertical'):
68
+ # Create a rectangular plot for the speedometer background
69
+
70
+ if horizontal_or_vertical == 'horizontal':
71
+ self.fig, self.ax = plt.subplots(figsize=(6, 3))
72
+ self.direction = 'horizontal'
73
+ else:
74
+ # Default to vertical if not specified
75
+ self.fig, self.ax = plt.subplots(figsize=(3, 6))
76
+ self.direction = 'vertical'
77
+
78
+ self.ax.set_xlim(0, 1)
79
+ self.ax.set_ylim(0, 1)
80
+
81
+ def plot_background(self):
82
+ # Define the ranges for red, yellow, and green
83
+
84
+ if self.direction == 'horizontal':
85
+ # Horizontal speedometer
86
+ self.ax.fill_between([0, 1/3], 0, 1, color='green', alpha=0.7)
87
+ self.ax.fill_between([1/3, 2/3], 0, 1, color='yellow', alpha=0.7)
88
+ self.ax.fill_between([2/3, 1], 0, 1, color='red', alpha=0.7)
89
+ else:
90
+ # Vertical speedometer
91
+ self.ax.fill_between([0, 1], 0, 1/3, color='green', alpha=0.7)
92
+ self.ax.fill_between([0, 1], 1/3, 2/3, color='yellow', alpha=0.7)
93
+ self.ax.fill_between([0, 1], 2/3, 1, color='red', alpha=0.7)
94
+
95
+ # Remove grid and ticks for a clean look
96
+ self.ax.grid(False)
97
+ self.ax.set_xticks([])
98
+ self.ax.set_yticks([])
99
+
100
+ def plot_needle(self, value):
101
+ # Add a needle to indicate a specific value
102
+ width = 0.01 # Needle width
103
+
104
+ if self.direction == 'horizontal':
105
+ # Horizontal speedometer
106
+ self.ax.fill([value-width, value+width, value+width, value-width],
107
+ [0.25, 0.25, 0.9, 0.9], color='black', linewidth=2)
108
+ else:
109
+ # Vertical speedometer
110
+ self.ax.fill([0, 1, 1, 0],
111
+ [value-width, value-width, value+width, value+width], color='black', linewidth=2)
112
+
113
+ def plot_text(self, text, value):
114
+ # Add text to the speedometer
115
+ self.ax.text(0.5, 1.15, text, fontsize=12, ha='center', va='center', color='black')
116
+
117
+
118
+
119
+
120
+ if __name__ == "__main__":
121
+ # Test the speedometer function
122
+ fig = Semi_Circle_Gauge()
123
+ import matplotlib.animation as animation
124
+
125
+ def update(frame):
126
+ fig.ax.clear()
127
+ fig.plot_background() # Reinitialize the speedometer to clear previous needle
128
+ fig.plot_needle(frame)
129
+ fig.plot_text("Danger: {:.2f}".format(frame), frame)
130
+
131
+ # Create an animation with values ranging from 0 to π
132
+ ani = animation.FuncAnimation(fig.fig, update, frames=np.linspace(0, np.pi, 100), interval=50)
133
+
134
+ plt.show()
135
+ pass