physplot 0.1.0.post1__tar.gz → 0.1.2__tar.gz

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.
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: physplot
3
+ Version: 0.1.2
4
+ Summary: Plotting, curve fitting, and error propagation tools for physics labs
5
+ Author: Anant Mathur
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: numpy
8
+ Requires-Dist: matplotlib
9
+ Requires-Dist: scipy
10
+ Requires-Dist: sympy
11
+
12
+ # physplot
13
+
14
+ Plotting and error propagation tools related to lab work for students.
15
+
16
+ ## Usage
17
+
18
+ Import using: from physplot import Graph, Error, Propagation
19
+
20
+ 1. Graphing:
21
+ - Create figure and plot axes: Graph.plot_details(#row_plots, #col_plots, width, height, ...)
22
+ - Create Graph object: graph_obj = Graph(axs[#row, #col], x, y)
23
+ - Plot and decorate the object: obj.grapher(...) or Graph.grapher(obj, ...)
24
+ - Show graph: Graph.show()
25
+ 2. Error Data:
26
+ - Create Error object: err_obj = Error(data)
27
+ - Calculate error (can add certain constraints): err = Error.err(err_obj, ...) or err_obj.err(...)
28
+ 3. Error Propagation:
29
+ - Create Propagation object with 2 methods:
30
+ - Use Error object: prop_obj = Propagation({variable : err_obj}, ...)
31
+ - Use external error data: prop_obj = Propagation(manual_data = data, manual_err = err, ...)
32
+ - Calculate propagated error: Propagation.propagator(prop_obj, expression, ...) or prop_obj.propagator(expression, ...)
33
+
34
+ ## Dependencies
35
+ Requires numpy, matplotlib, scipy and sympy (come with installation of physplot)
36
+
37
+ ## Installation
38
+ ```bash
39
+ pip install physplot
@@ -0,0 +1,28 @@
1
+ # physplot
2
+
3
+ Plotting and error propagation tools related to lab work for students.
4
+
5
+ ## Usage
6
+
7
+ Import using: from physplot import Graph, Error, Propagation
8
+
9
+ 1. Graphing:
10
+ - Create figure and plot axes: Graph.plot_details(#row_plots, #col_plots, width, height, ...)
11
+ - Create Graph object: graph_obj = Graph(axs[#row, #col], x, y)
12
+ - Plot and decorate the object: obj.grapher(...) or Graph.grapher(obj, ...)
13
+ - Show graph: Graph.show()
14
+ 2. Error Data:
15
+ - Create Error object: err_obj = Error(data)
16
+ - Calculate error (can add certain constraints): err = Error.err(err_obj, ...) or err_obj.err(...)
17
+ 3. Error Propagation:
18
+ - Create Propagation object with 2 methods:
19
+ - Use Error object: prop_obj = Propagation({variable : err_obj}, ...)
20
+ - Use external error data: prop_obj = Propagation(manual_data = data, manual_err = err, ...)
21
+ - Calculate propagated error: Propagation.propagator(prop_obj, expression, ...) or prop_obj.propagator(expression, ...)
22
+
23
+ ## Dependencies
24
+ Requires numpy, matplotlib, scipy and sympy (come with installation of physplot)
25
+
26
+ ## Installation
27
+ ```bash
28
+ pip install physplot
@@ -1,5 +1,5 @@
1
1
  import numpy as np
2
- from typing import Dict, Sequence, Union
2
+ from typing import Sequence, Union
3
3
 
4
4
  NumberArray = Union[float, int, np.ndarray, Sequence[float]]
5
5
 
@@ -15,6 +15,7 @@ class Graph:
15
15
  self.x_axis_mean, self.x_err_mean = self._normalize_axis(x_axis, x_err)
16
16
  self.y_axis_mean, self.y_err_mean = self._normalize_axis(y_axis, y_err)
17
17
  self.parameters = None
18
+ self.r_value = None
18
19
 
19
20
  @staticmethod
20
21
  def plot_details(rows, cols, x_size, y_size, text=None, fontsize=None):
@@ -33,7 +34,7 @@ class Graph:
33
34
  x_tick_start=None, x_tick_end=None, x_tick_step=None, y_tick_start=None,
34
35
  y_tick_end=None, y_tick_step=None, line_fit_bool=False,
35
36
  curve_fit_bool=False, fit_func=None, p0=None, fit_colors=None, fit_labels=None,
36
- minor_ticks=True):
37
+ minor_ticks=True, r_bool = False):
37
38
 
38
39
  if self.y_err is not None or self.x_err is not None:
39
40
  self._handle_errors()
@@ -43,7 +44,7 @@ class Graph:
43
44
  if line_fit_bool:
44
45
  self._fit_line()
45
46
  if curve_fit_bool:
46
- self._fit_curve(fit_func, p0, fit_colors, fit_labels)
47
+ self._fit_curve(fit_func, p0, fit_colors, fit_labels, r_bool)
47
48
  self._set_ticks(x_tick_start, x_tick_end, x_tick_step,
48
49
  y_tick_start, y_tick_end, y_tick_step, minor_ticks)
49
50
  self._finalize_plot(title, x_label, y_label, text)
@@ -70,7 +71,7 @@ class Graph:
70
71
  fit_line = np.polyval(self.parameters, self.x_axis_mean)
71
72
  self.axis.plot(self.x_axis_mean, fit_line, color='grey', linestyle='dashed', label='Linear Fit')
72
73
 
73
- def _fit_curve(self, fit_func, p0, fit_colors, fit_labels):
74
+ def _fit_curve(self, fit_func, p0, fit_colors, fit_labels, r_bool):
74
75
  if fit_func is None:
75
76
  raise ValueError("Provide fit_func for curve fitting.")
76
77
  fit_funcs = fit_func if isinstance(fit_func, (list, tuple)) else [fit_func]
@@ -82,10 +83,14 @@ class Graph:
82
83
 
83
84
  for i, func in enumerate(fit_funcs):
84
85
  try:
85
- popt, _ = curve_fit(func, self.x_axis_mean, self.y_axis_mean, p0=p0s[i])
86
+ popt, _ = curve_fit(func, self.x_axis_mean, self.y_axis_mean, p0=p0s[i], absolute_sigma = True)
86
87
  self.parameters.append(popt)
87
88
  fitted_y = func(x_fit, *popt)
88
89
  self.axis.plot(x_fit, fitted_y, color=fit_colors[i], linestyle='dashed', label=fit_labels[i])
90
+
91
+ if r_bool:
92
+ self.r_value = np.corrcoef(self.x_axis_mean, self.y_axis_mean)[0, 1]
93
+
89
94
  except Exception as e:
90
95
  print(f"Curve Fit {fit_labels[i]} failed: {e}")
91
96
  self.parameters.append(None)
@@ -159,4 +164,16 @@ class Graph:
159
164
  return err_array
160
165
  else:
161
166
  collapsed = np.nanmean(err_array, axis=tuple(range(1, err_array.ndim)))
162
- return collapsed
167
+ return collapsed
168
+
169
+ @staticmethod
170
+ def show():
171
+ plt.show()
172
+
173
+ @staticmethod
174
+ def savefig(filepath, dpi):
175
+ plt.savefig(filepath, dpi = dpi)
176
+
177
+ def label(self, text: str, x, y, v_al = None, h_al = None):
178
+ self.axis.text(x, y, f"{text}", transform = self.axis.transAxes, fontsize = 12,
179
+ verticalalignment = v_al, horizontalalignment = h_al)
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: physplot
3
+ Version: 0.1.2
4
+ Summary: Plotting, curve fitting, and error propagation tools for physics labs
5
+ Author: Anant Mathur
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: numpy
8
+ Requires-Dist: matplotlib
9
+ Requires-Dist: scipy
10
+ Requires-Dist: sympy
11
+
12
+ # physplot
13
+
14
+ Plotting and error propagation tools related to lab work for students.
15
+
16
+ ## Usage
17
+
18
+ Import using: from physplot import Graph, Error, Propagation
19
+
20
+ 1. Graphing:
21
+ - Create figure and plot axes: Graph.plot_details(#row_plots, #col_plots, width, height, ...)
22
+ - Create Graph object: graph_obj = Graph(axs[#row, #col], x, y)
23
+ - Plot and decorate the object: obj.grapher(...) or Graph.grapher(obj, ...)
24
+ - Show graph: Graph.show()
25
+ 2. Error Data:
26
+ - Create Error object: err_obj = Error(data)
27
+ - Calculate error (can add certain constraints): err = Error.err(err_obj, ...) or err_obj.err(...)
28
+ 3. Error Propagation:
29
+ - Create Propagation object with 2 methods:
30
+ - Use Error object: prop_obj = Propagation({variable : err_obj}, ...)
31
+ - Use external error data: prop_obj = Propagation(manual_data = data, manual_err = err, ...)
32
+ - Calculate propagated error: Propagation.propagator(prop_obj, expression, ...) or prop_obj.propagator(expression, ...)
33
+
34
+ ## Dependencies
35
+ Requires numpy, matplotlib, scipy and sympy (come with installation of physplot)
36
+
37
+ ## Installation
38
+ ```bash
39
+ pip install physplot
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "physplot"
7
- version = "0.1.0.post1"
7
+ version = "0.1.2"
8
8
  description = "Plotting, curve fitting, and error propagation tools for physics labs"
9
9
  authors = [{name = "Anant Mathur"}]
10
10
  readme = { file = "README.md", content-type = "text/markdown" }
@@ -1,18 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: physplot
3
- Version: 0.1.0.post1
4
- Summary: Plotting, curve fitting, and error propagation tools for physics labs
5
- Author: Anant Mathur
6
- Description-Content-Type: text/markdown
7
- Requires-Dist: numpy
8
- Requires-Dist: matplotlib
9
- Requires-Dist: scipy
10
- Requires-Dist: sympy
11
-
12
- # physplot
13
-
14
- Plotting and error propagation tools for physics labs.
15
-
16
- ## Installation
17
- ```bash
18
- pip install physplot
@@ -1,7 +0,0 @@
1
- # physplot
2
-
3
- Plotting and error propagation tools for physics labs.
4
-
5
- ## Installation
6
- ```bash
7
- pip install physplot
@@ -1,18 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: physplot
3
- Version: 0.1.0.post1
4
- Summary: Plotting, curve fitting, and error propagation tools for physics labs
5
- Author: Anant Mathur
6
- Description-Content-Type: text/markdown
7
- Requires-Dist: numpy
8
- Requires-Dist: matplotlib
9
- Requires-Dist: scipy
10
- Requires-Dist: sympy
11
-
12
- # physplot
13
-
14
- Plotting and error propagation tools for physics labs.
15
-
16
- ## Installation
17
- ```bash
18
- pip install physplot
File without changes