plotly-lite 0.1.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotly-lite
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: lite version wrapper on plotly for quick utilization for scientific graphs
5
5
  Home-page: https://github.com/Shahrukh-Chishti/plotly-lite
6
6
  Author: Shahrukh Chishti
@@ -218,9 +218,137 @@ Dynamic: home-page
218
218
  Dynamic: license-file
219
219
  Dynamic: requires-python
220
220
 
221
- # plotly-lite
222
- lite version wrapper on plotly
223
- * quick utilization
224
- * compare
225
- * heatmap
226
- * trajectories
221
+ # plotting.py
222
+
223
+ A lightweight Plotly wrapper for fast prototyping of common scientific and ML charts — minimal boilerplate, consistent styling out of the box.
224
+
225
+ ## Installation
226
+
227
+ ```bash
228
+ pip install plotly kaleido scikit-learn matplotlib numpy
229
+ ```
230
+
231
+ ## Usage
232
+
233
+ ```python
234
+ from plotting import plotBox, plotCompare, plotHeatmap # etc.
235
+ ```
236
+
237
+ Every function accepts a `title`, `x_label` / `y_label`, an optional `size=(height, width)` tuple, and two output modes:
238
+
239
+ | Param | Default | Effect |
240
+ |---|---|---|
241
+ | `html=False` | `False` | Save a self-contained `.html` file instead of displaying inline |
242
+ | `export=None` | `None` | Save a static image — `'png'`, `'svg'`, `'pdf'`, … |
243
+
244
+ ---
245
+
246
+ ## Functions
247
+
248
+ ### `plotBox` — grouped box plots
249
+
250
+ ```python
251
+ plotBox(
252
+ {'Model A': array_a, 'Model B': array_b},
253
+ title='Accuracy by Model',
254
+ y_label='Accuracy',
255
+ ylimit=[0.5, 1.0],
256
+ )
257
+ ```
258
+
259
+ ### `plotCompare` — line chart with shared x axis
260
+
261
+ Best for training curves, time series, anything where all series share the same x values.
262
+
263
+ ```python
264
+ epochs = np.arange(1, 51)
265
+ plotCompare(
266
+ epochs,
267
+ {'Train': train_loss, 'Val': val_loss},
268
+ title='Loss Curves',
269
+ x_label='Epoch', y_label='Loss',
270
+ )
271
+ ```
272
+
273
+ ### `plotCombine` — multi-series with independent x arrays
274
+
275
+ Use when each series has its own x domain or resolution.
276
+
277
+ ```python
278
+ plotCombine(
279
+ {'sin': (t, np.sin(t)), 'cos': (t, np.cos(t))},
280
+ title='Trig Functions',
281
+ mode='lines', # 'markers' or 'lines+markers' also accepted
282
+ )
283
+ ```
284
+
285
+ ### `plotScatter` — scatter plot, shared x
286
+
287
+ ```python
288
+ plotScatter(
289
+ x_vals,
290
+ {'Group A': y_a, 'Group B': y_b},
291
+ title='Feature vs Target',
292
+ dot_size=4,
293
+ )
294
+ ```
295
+
296
+ ### `plotMap` — raw heatmap (no interpolation)
297
+
298
+ Good for confusion matrices, correlation grids, any discrete 2-D matrix.
299
+
300
+ ```python
301
+ plotMap(z=matrix, x=col_labels, y=row_labels, title='Confusion Matrix')
302
+ ```
303
+
304
+ ### `plotHeatmap` — contour plot with heatmap fill
305
+
306
+ For continuous surfaces where you want to highlight level sets.
307
+
308
+ ```python
309
+ plotHeatmap(z=Z, x=grid_x, y=grid_y, title='Loss Surface', ncontours=15)
310
+ ```
311
+
312
+ ### `plotTrajectory` — 2-D paths with time-varying marker size
313
+
314
+ Markers grow over time so you can track direction at a glance.
315
+
316
+ ```python
317
+ plotTrajectory(
318
+ evo=np.arange(T), # drives marker size (normalised to [0, 15])
319
+ plot={'Agent': path}, # path is an (N, 2) array
320
+ title='Agent Trajectory',
321
+ )
322
+ ```
323
+
324
+ ### `plotOptimization` — loss landscape + optimiser paths
325
+
326
+ Overlays one or more optimiser trajectories on a filled contour map.
327
+
328
+ ```python
329
+ plotOptimization(
330
+ z=loss_surface, x=w1, y=w2,
331
+ paths={'SGD': sgd_path, 'Adam': adam_path},
332
+ title='Optimiser Comparison',
333
+ )
334
+ ```
335
+
336
+ ### `viewPCA` — 2-D PCA projection *(matplotlib)*
337
+
338
+ Reduces high-dimensional data to 2 components and colours points by a given index.
339
+
340
+ ```python
341
+ viewPCA(X, index=labels, title='PCA Projection', x='PC 1', y='PC 2')
342
+ ```
343
+
344
+ ---
345
+
346
+ ## Exporting
347
+
348
+ ```python
349
+ # Save a PNG (written twice to avoid kaleido race condition)
350
+ plotCompare(epochs, data, title='loss', export='png')
351
+
352
+ # Save an interactive HTML file
353
+ plotCompare(epochs, data, title='loss', html=True)
354
+ ```
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotly-lite
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: lite version wrapper on plotly for quick utilization for scientific graphs
5
5
  Home-page: https://github.com/Shahrukh-Chishti/plotly-lite
6
6
  Author: Shahrukh Chishti
@@ -218,9 +218,137 @@ Dynamic: home-page
218
218
  Dynamic: license-file
219
219
  Dynamic: requires-python
220
220
 
221
- # plotly-lite
222
- lite version wrapper on plotly
223
- * quick utilization
224
- * compare
225
- * heatmap
226
- * trajectories
221
+ # plotting.py
222
+
223
+ A lightweight Plotly wrapper for fast prototyping of common scientific and ML charts — minimal boilerplate, consistent styling out of the box.
224
+
225
+ ## Installation
226
+
227
+ ```bash
228
+ pip install plotly kaleido scikit-learn matplotlib numpy
229
+ ```
230
+
231
+ ## Usage
232
+
233
+ ```python
234
+ from plotting import plotBox, plotCompare, plotHeatmap # etc.
235
+ ```
236
+
237
+ Every function accepts a `title`, `x_label` / `y_label`, an optional `size=(height, width)` tuple, and two output modes:
238
+
239
+ | Param | Default | Effect |
240
+ |---|---|---|
241
+ | `html=False` | `False` | Save a self-contained `.html` file instead of displaying inline |
242
+ | `export=None` | `None` | Save a static image — `'png'`, `'svg'`, `'pdf'`, … |
243
+
244
+ ---
245
+
246
+ ## Functions
247
+
248
+ ### `plotBox` — grouped box plots
249
+
250
+ ```python
251
+ plotBox(
252
+ {'Model A': array_a, 'Model B': array_b},
253
+ title='Accuracy by Model',
254
+ y_label='Accuracy',
255
+ ylimit=[0.5, 1.0],
256
+ )
257
+ ```
258
+
259
+ ### `plotCompare` — line chart with shared x axis
260
+
261
+ Best for training curves, time series, anything where all series share the same x values.
262
+
263
+ ```python
264
+ epochs = np.arange(1, 51)
265
+ plotCompare(
266
+ epochs,
267
+ {'Train': train_loss, 'Val': val_loss},
268
+ title='Loss Curves',
269
+ x_label='Epoch', y_label='Loss',
270
+ )
271
+ ```
272
+
273
+ ### `plotCombine` — multi-series with independent x arrays
274
+
275
+ Use when each series has its own x domain or resolution.
276
+
277
+ ```python
278
+ plotCombine(
279
+ {'sin': (t, np.sin(t)), 'cos': (t, np.cos(t))},
280
+ title='Trig Functions',
281
+ mode='lines', # 'markers' or 'lines+markers' also accepted
282
+ )
283
+ ```
284
+
285
+ ### `plotScatter` — scatter plot, shared x
286
+
287
+ ```python
288
+ plotScatter(
289
+ x_vals,
290
+ {'Group A': y_a, 'Group B': y_b},
291
+ title='Feature vs Target',
292
+ dot_size=4,
293
+ )
294
+ ```
295
+
296
+ ### `plotMap` — raw heatmap (no interpolation)
297
+
298
+ Good for confusion matrices, correlation grids, any discrete 2-D matrix.
299
+
300
+ ```python
301
+ plotMap(z=matrix, x=col_labels, y=row_labels, title='Confusion Matrix')
302
+ ```
303
+
304
+ ### `plotHeatmap` — contour plot with heatmap fill
305
+
306
+ For continuous surfaces where you want to highlight level sets.
307
+
308
+ ```python
309
+ plotHeatmap(z=Z, x=grid_x, y=grid_y, title='Loss Surface', ncontours=15)
310
+ ```
311
+
312
+ ### `plotTrajectory` — 2-D paths with time-varying marker size
313
+
314
+ Markers grow over time so you can track direction at a glance.
315
+
316
+ ```python
317
+ plotTrajectory(
318
+ evo=np.arange(T), # drives marker size (normalised to [0, 15])
319
+ plot={'Agent': path}, # path is an (N, 2) array
320
+ title='Agent Trajectory',
321
+ )
322
+ ```
323
+
324
+ ### `plotOptimization` — loss landscape + optimiser paths
325
+
326
+ Overlays one or more optimiser trajectories on a filled contour map.
327
+
328
+ ```python
329
+ plotOptimization(
330
+ z=loss_surface, x=w1, y=w2,
331
+ paths={'SGD': sgd_path, 'Adam': adam_path},
332
+ title='Optimiser Comparison',
333
+ )
334
+ ```
335
+
336
+ ### `viewPCA` — 2-D PCA projection *(matplotlib)*
337
+
338
+ Reduces high-dimensional data to 2 components and colours points by a given index.
339
+
340
+ ```python
341
+ viewPCA(X, index=labels, title='PCA Projection', x='PC 1', y='PC 2')
342
+ ```
343
+
344
+ ---
345
+
346
+ ## Exporting
347
+
348
+ ```python
349
+ # Save a PNG (written twice to avoid kaleido race condition)
350
+ plotCompare(epochs, data, title='loss', export='png')
351
+
352
+ # Save an interactive HTML file
353
+ plotCompare(epochs, data, title='loss', html=True)
354
+ ```
@@ -0,0 +1,134 @@
1
+ # plotting.py
2
+
3
+ A lightweight Plotly wrapper for fast prototyping of common scientific and ML charts — minimal boilerplate, consistent styling out of the box.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install plotly kaleido scikit-learn matplotlib numpy
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ from plotting import plotBox, plotCompare, plotHeatmap # etc.
15
+ ```
16
+
17
+ Every function accepts a `title`, `x_label` / `y_label`, an optional `size=(height, width)` tuple, and two output modes:
18
+
19
+ | Param | Default | Effect |
20
+ |---|---|---|
21
+ | `html=False` | `False` | Save a self-contained `.html` file instead of displaying inline |
22
+ | `export=None` | `None` | Save a static image — `'png'`, `'svg'`, `'pdf'`, … |
23
+
24
+ ---
25
+
26
+ ## Functions
27
+
28
+ ### `plotBox` — grouped box plots
29
+
30
+ ```python
31
+ plotBox(
32
+ {'Model A': array_a, 'Model B': array_b},
33
+ title='Accuracy by Model',
34
+ y_label='Accuracy',
35
+ ylimit=[0.5, 1.0],
36
+ )
37
+ ```
38
+
39
+ ### `plotCompare` — line chart with shared x axis
40
+
41
+ Best for training curves, time series, anything where all series share the same x values.
42
+
43
+ ```python
44
+ epochs = np.arange(1, 51)
45
+ plotCompare(
46
+ epochs,
47
+ {'Train': train_loss, 'Val': val_loss},
48
+ title='Loss Curves',
49
+ x_label='Epoch', y_label='Loss',
50
+ )
51
+ ```
52
+
53
+ ### `plotCombine` — multi-series with independent x arrays
54
+
55
+ Use when each series has its own x domain or resolution.
56
+
57
+ ```python
58
+ plotCombine(
59
+ {'sin': (t, np.sin(t)), 'cos': (t, np.cos(t))},
60
+ title='Trig Functions',
61
+ mode='lines', # 'markers' or 'lines+markers' also accepted
62
+ )
63
+ ```
64
+
65
+ ### `plotScatter` — scatter plot, shared x
66
+
67
+ ```python
68
+ plotScatter(
69
+ x_vals,
70
+ {'Group A': y_a, 'Group B': y_b},
71
+ title='Feature vs Target',
72
+ dot_size=4,
73
+ )
74
+ ```
75
+
76
+ ### `plotMap` — raw heatmap (no interpolation)
77
+
78
+ Good for confusion matrices, correlation grids, any discrete 2-D matrix.
79
+
80
+ ```python
81
+ plotMap(z=matrix, x=col_labels, y=row_labels, title='Confusion Matrix')
82
+ ```
83
+
84
+ ### `plotHeatmap` — contour plot with heatmap fill
85
+
86
+ For continuous surfaces where you want to highlight level sets.
87
+
88
+ ```python
89
+ plotHeatmap(z=Z, x=grid_x, y=grid_y, title='Loss Surface', ncontours=15)
90
+ ```
91
+
92
+ ### `plotTrajectory` — 2-D paths with time-varying marker size
93
+
94
+ Markers grow over time so you can track direction at a glance.
95
+
96
+ ```python
97
+ plotTrajectory(
98
+ evo=np.arange(T), # drives marker size (normalised to [0, 15])
99
+ plot={'Agent': path}, # path is an (N, 2) array
100
+ title='Agent Trajectory',
101
+ )
102
+ ```
103
+
104
+ ### `plotOptimization` — loss landscape + optimiser paths
105
+
106
+ Overlays one or more optimiser trajectories on a filled contour map.
107
+
108
+ ```python
109
+ plotOptimization(
110
+ z=loss_surface, x=w1, y=w2,
111
+ paths={'SGD': sgd_path, 'Adam': adam_path},
112
+ title='Optimiser Comparison',
113
+ )
114
+ ```
115
+
116
+ ### `viewPCA` — 2-D PCA projection *(matplotlib)*
117
+
118
+ Reduces high-dimensional data to 2 components and colours points by a given index.
119
+
120
+ ```python
121
+ viewPCA(X, index=labels, title='PCA Projection', x='PC 1', y='PC 2')
122
+ ```
123
+
124
+ ---
125
+
126
+ ## Exporting
127
+
128
+ ```python
129
+ # Save a PNG (written twice to avoid kaleido race condition)
130
+ plotCompare(epochs, data, title='loss', export='png')
131
+
132
+ # Save an interactive HTML file
133
+ plotCompare(epochs, data, title='loss', html=True)
134
+ ```
@@ -0,0 +1,361 @@
1
+ """
2
+ plotting.py — Lightweight Plotly wrapper for fast prototyping.
3
+
4
+ Provides a set of convenience functions for common chart types:
5
+ - Box plots (plotBox)
6
+ - Multi-line / scatter (plotCombine, plotCompare, plotScatter)
7
+ - Heatmaps & contours (plotMap, plotHeatmap)
8
+ - Trajectory & optim. (plotTrajectory, plotOptimization)
9
+ - PCA projection (viewPCA)
10
+
11
+ All Plotly-based functions share a common `render()` helper that
12
+ applies consistent styling, optional export, and HTML/inline output.
13
+ """
14
+
15
+ import plotly.offline as py
16
+ import plotly.graph_objs as go
17
+ import matplotlib.pyplot as plt
18
+ import time
19
+
20
+
21
+ # ---------------------------------------------------------------------------
22
+ # Internal helpers
23
+ # ---------------------------------------------------------------------------
24
+
25
+ def render(fig, title, size, html, export):
26
+ """
27
+ Apply shared layout settings and output the figure.
28
+
29
+ Parameters
30
+ ----------
31
+ fig : go.Figure — the Plotly figure to render
32
+ title : str — chart title (also used as the output filename)
33
+ size : tuple | None — (height, width) in pixels; None keeps Plotly defaults
34
+ html : bool — if True, write an interactive .html file instead of
35
+ displaying inline (useful in non-notebook environments)
36
+ export : str | None — static image format to save, e.g. 'png', 'svg', 'pdf';
37
+ None skips static export. Written twice with a short
38
+ sleep to work around kaleido race conditions.
39
+ """
40
+ # Global font size and tight margins (overridden below after optional export)
41
+ fig.update_layout(font={'size': 30})
42
+ fig.update_layout(margin_t=10, margin_r=10)
43
+
44
+ # Legend: top-right corner, semi-transparent background
45
+ fig.update_layout(legend=dict(
46
+ yanchor="top", y=0.99,
47
+ xanchor="right", x=0.99,
48
+ bgcolor="rgba(0,0,0,.05)"
49
+ ))
50
+
51
+ # Optional fixed canvas size
52
+ if size:
53
+ height, width = size
54
+ fig.update_layout(width=width, height=height)
55
+
56
+ # Static image export (written twice to avoid kaleido blank-frame bug)
57
+ if export:
58
+ fig.write_image('./' + title + '.' + export)
59
+ time.sleep(2)
60
+ fig.write_image('./' + title + '.' + export)
61
+
62
+ # Add title and restore top margin now that image export is done
63
+ fig.update_layout(title=title)
64
+ fig.update_layout(margin_t=100)
65
+
66
+ if html:
67
+ # Save a self-contained interactive HTML file
68
+ fig.write_html('./' + title + '.html')
69
+ else:
70
+ # Display inline (Jupyter / Colab)
71
+ py.iplot(fig)
72
+
73
+
74
+ # ---------------------------------------------------------------------------
75
+ # Chart functions
76
+ # ---------------------------------------------------------------------------
77
+
78
+ def plotBox(plot, title=None, x_label=None, y_label=None,
79
+ size=None, html=False, export=None, ylimit=None):
80
+ """
81
+ Render a grouped box-plot from a dictionary of distributions.
82
+
83
+ Parameters
84
+ ----------
85
+ plot : dict[str, array-like]
86
+ Keys become box labels; values are the raw data arrays.
87
+ Example: {'GroupA': [1,2,3], 'GroupB': [4,5,6]}
88
+ title : str — chart title & export filename
89
+ x_label : str — x-axis label
90
+ y_label : str — y-axis label
91
+ size : tuple — (height, width) in pixels
92
+ html : bool — write HTML instead of displaying inline
93
+ export : str | None — static export format ('png', 'svg', …)
94
+ ylimit : list | None — [y_min, y_max] to fix the y-axis range
95
+ """
96
+ fig = go.Figure()
97
+ for name, dist in plot.items():
98
+ fig.add_trace(go.Box(y=dist, name=name))
99
+
100
+ fig.update_layout(xaxis_title=x_label, yaxis_title=y_label)
101
+ fig.update_layout(showlegend=False) # Labels already on x-axis
102
+ fig.update_layout(yaxis_range=ylimit)
103
+ render(fig, title, size, html, export)
104
+
105
+
106
+ def plotCombine(plot, title=None, x_label=None, y_label=None,
107
+ mode='lines', width=5, size=None,
108
+ html=False, export=None, legend=True):
109
+ """
110
+ Overlay multiple (x, y) series on a single chart.
111
+
112
+ Unlike `plotCompare` (which shares a common x array), each series
113
+ here supplies its own x values — useful when series have different
114
+ resolutions or domains.
115
+
116
+ Parameters
117
+ ----------
118
+ plot : dict[str, (array-like, array-like)]
119
+ Keys are series names; values are (x, y) tuples.
120
+ Example: {'sin': (x, np.sin(x)), 'cos': (x, np.cos(x))}
121
+ mode : str — Plotly scatter mode: 'lines', 'markers', 'lines+markers'
122
+ width : int — line width and marker size
123
+ (remaining params same as plotBox)
124
+ """
125
+ fig = go.Figure()
126
+ for name, (x, y) in plot.items():
127
+ fig.add_trace(go.Scatter(
128
+ x=x, y=y, name=name, mode=mode,
129
+ line={'width': width}, marker={'size': width}
130
+ ))
131
+
132
+ fig.update_layout(xaxis_title=x_label, yaxis_title=y_label)
133
+ fig.update_layout(showlegend=legend)
134
+ render(fig, title, size, html, export)
135
+
136
+
137
+ def plotScatter(x, plot, title=None, x_label=None, y_label=None,
138
+ size=None, dot_size=1, html=False, export=None, legend=True):
139
+ """
140
+ Scatter plot with a shared x array and multiple y series.
141
+
142
+ Parameters
143
+ ----------
144
+ x : array-like — shared x values for all series
145
+ plot : dict[str, array-like] — series name → y values
146
+ dot_size : int — marker size in pixels
147
+ (remaining params same as plotBox)
148
+ """
149
+ fig = go.Figure()
150
+ for name, values in plot.items():
151
+ fig.add_trace(go.Scatter(
152
+ x=x, y=values, name=name,
153
+ mode='markers', marker={'size': dot_size}
154
+ ))
155
+
156
+ fig.update_layout(xaxis_title=x_label, yaxis_title=y_label)
157
+ fig.update_layout(showlegend=legend)
158
+ render(fig, title, size, html, export)
159
+
160
+
161
+ def plotCompare(x, plot, title=None, x_label=None, y_label=None,
162
+ width=5, size=None, html=False, export=None, legend=True):
163
+ """
164
+ Line chart comparing multiple y series against a single shared x array.
165
+
166
+ Use this when all series share the same x axis (e.g. time, epochs).
167
+ For series with different x domains, use `plotCombine` instead.
168
+
169
+ Parameters
170
+ ----------
171
+ x : array-like — shared x axis
172
+ plot : dict[str, array-like] — series name → y values
173
+ width : int — line width
174
+ (remaining params same as plotBox)
175
+ """
176
+ fig = go.Figure()
177
+ for name, values in plot.items():
178
+ fig.add_trace(go.Scatter(x=x, y=values, name=name, line={'width': width}))
179
+
180
+ fig.update_layout(xaxis_title=x_label, yaxis_title=y_label)
181
+ fig.update_layout(showlegend=legend)
182
+ render(fig, title, size, html, export)
183
+
184
+
185
+ def plotMap(z, x, y, title=None, xaxis=None, yaxis=None,
186
+ size=None, html=False, export=None, legend=True, log=False):
187
+ """
188
+ Render a 2-D heatmap (flat colour blocks, no interpolation).
189
+
190
+ Parameters
191
+ ----------
192
+ z : 2-D array-like — matrix of values (rows = y, cols = x)
193
+ x : array-like — x-axis tick labels / coordinates
194
+ y : array-like — y-axis tick labels / coordinates
195
+ xaxis : str — x-axis label
196
+ yaxis : str — y-axis label
197
+ log : bool — use log scale on both axes
198
+ (remaining params same as plotBox)
199
+ """
200
+ fig = go.Figure()
201
+ heatmap = go.Heatmap(z=z, y=y, x=x)
202
+ fig.add_trace(heatmap)
203
+
204
+ fig.update_layout(showlegend=legend)
205
+ fig.update_traces(showscale=legend)
206
+ fig.update_layout(coloraxis_showscale=legend)
207
+ fig.update_layout(xaxis_title=xaxis, yaxis_title=yaxis)
208
+
209
+ if log:
210
+ fig.update_xaxes(type="log")
211
+ fig.update_yaxes(type="log")
212
+
213
+ render(fig, title, size, html, export)
214
+
215
+
216
+ def plotHeatmap(z, x, y, title=None, xaxis=None, yaxis=None,
217
+ size=None, html=False, export=None,
218
+ ncontours=10, legend=True, log=False):
219
+ """
220
+ Contour plot with heatmap colour-fill (smoothed / interpolated).
221
+
222
+ Prefer this over `plotMap` when the underlying surface is continuous
223
+ and you want to highlight level sets (iso-lines).
224
+
225
+ Parameters
226
+ ----------
227
+ z : 2-D array-like — surface values
228
+ x : array-like — x coordinates
229
+ y : array-like — y coordinates
230
+ ncontours : int — number of contour levels (default 10)
231
+ (remaining params same as plotMap)
232
+ """
233
+ fig = go.Figure()
234
+ start = z.min()
235
+ end = z.max()
236
+ contours = dict(start=start, end=end, size=(end - start) / ncontours)
237
+ heatmap = go.Contour(z=z, y=y, x=x, contours_coloring='heatmap', contours=contours)
238
+ fig.add_trace(heatmap)
239
+
240
+ fig.update_layout(showlegend=legend)
241
+ fig.update_traces(showscale=legend)
242
+ fig.update_layout(coloraxis_showscale=legend)
243
+ fig.update_layout(xaxis_title=xaxis, yaxis_title=yaxis)
244
+
245
+ if log:
246
+ fig.update_xaxes(type="log")
247
+ fig.update_yaxes(type="log")
248
+
249
+ render(fig, title, size, html, export)
250
+
251
+
252
+ def plotTrajectory(evo, plot, title=None, x_label=None, y_label=None,
253
+ size=None, html=False, export=None, legend=False):
254
+ """
255
+ Animate 2-D paths with marker sizes that grow over time.
256
+
257
+ Useful for visualising agent trajectories, particle paths, or
258
+ any sequential 2-D motion where recency should be visually salient.
259
+
260
+ Parameters
261
+ ----------
262
+ evo : array-like — 1-D sequence whose values drive marker
263
+ sizes (normalised to [0, 15]); typically
264
+ frame indices or timestamps
265
+ plot : dict[str, ndarray] — name → (N, 2) array of (x, y) positions
266
+ (remaining params same as plotBox)
267
+ """
268
+ fig = go.Figure()
269
+ # Normalise evolution values so marker sizes stay in a readable range
270
+ evo = evo / max(evo) * 15
271
+
272
+ for name, path in plot.items():
273
+ fig.add_trace(go.Scatter(
274
+ x=path[:, 0], y=path[:, 1], name=name,
275
+ mode='lines+markers',
276
+ marker={'size': evo},
277
+ line={'width': 5}
278
+ ))
279
+
280
+ fig.update_layout(xaxis_title=x_label, yaxis_title=y_label)
281
+ fig.update_layout(showlegend=legend)
282
+ render(fig, title, size, html, export)
283
+
284
+
285
+ def plotOptimization(z, x, y, paths, title=None, xaxis=None, yaxis=None,
286
+ size=None, html=False, export=None, legend=False, log=False):
287
+ """
288
+ Visualise optimiser trajectories overlaid on a loss-landscape contour.
289
+
290
+ The loss surface is drawn as a filled contour map; each optimiser path
291
+ is drawn as a line whose markers grow linearly so you can track progress
292
+ from start (small dot) to end (large dot).
293
+
294
+ Parameters
295
+ ----------
296
+ z : 2-D array-like — loss surface values
297
+ x : array-like — x-axis grid values (e.g. weight₁ range)
298
+ y : array-like — y-axis grid values (e.g. weight₂ range)
299
+ paths : dict[str, ndarray] — optimiser name → (N, 2) array of (x, y)
300
+ parameter positions at each step
301
+ (remaining params same as plotMap)
302
+ """
303
+ fig = go.Figure()
304
+
305
+ # Background: loss surface as a filled contour map
306
+ heatmap = go.Contour(z=z, y=y, x=x, name='loss', contours_coloring='heatmap')
307
+ fig.add_trace(heatmap)
308
+ fig.update_layout(xaxis_title=xaxis, yaxis_title=yaxis)
309
+
310
+ # Overlay each optimiser path with linearly growing markers
311
+ for name, path in paths.items():
312
+ evo = [i * 15 / len(path) for i in range(len(path))]
313
+ fig.add_trace(go.Scatter(
314
+ x=path[:, 0], y=path[:, 1], name=name,
315
+ mode='lines+markers',
316
+ marker={'size': evo},
317
+ line={'width': 3}
318
+ ))
319
+
320
+ fig.update_layout(showlegend=legend)
321
+ if log:
322
+ fig.update_xaxes(type="log")
323
+ fig.update_yaxes(type="log")
324
+
325
+ render(fig, title, size, html, export)
326
+
327
+
328
+ # ---------------------------------------------------------------------------
329
+ # Matplotlib helpers
330
+ # ---------------------------------------------------------------------------
331
+
332
+ def viewPCA(X, index, size=(8, 6), title=None, x=None, y=None):
333
+ """
334
+ Project high-dimensional data to 2-D via PCA and render a scatter plot.
335
+
336
+ Uses matplotlib (not Plotly) so it renders without a running Plotly server.
337
+ Points are coloured by `index`, making it easy to spot clusters.
338
+
339
+ Parameters
340
+ ----------
341
+ X : array-like, shape (n_samples, n_features) — input data matrix
342
+ index : array-like, shape (n_samples,) — colour values per point
343
+ (e.g. cluster labels, targets)
344
+ size : tuple — figure size as (width, height) in inches (default (8, 6))
345
+ title : str — plot title
346
+ x : str — x-axis label (PCA component 1)
347
+ y : str — y-axis label (PCA component 2)
348
+ """
349
+ from sklearn.decomposition import PCA
350
+
351
+ # Fit PCA and reduce to 2 components
352
+ pca = PCA(n_components=2)
353
+ X_pca = pca.fit_transform(X)
354
+
355
+ plt.figure(figsize=size)
356
+ plt.scatter(X_pca[:, 0], X_pca[:, 1], c=index, cmap='viridis')
357
+ plt.xlabel(x)
358
+ plt.ylabel(y)
359
+ plt.title(title)
360
+ plt.colorbar(label='index')
361
+ plt.show()
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "plotly-lite" # must be unique on PyPI
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "lite version wrapper on plotly for quick utilization for scientific graphs"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -9,7 +9,7 @@ def load_requirements(path):
9
9
 
10
10
  setup(name='Plotly-Lite',
11
11
  author='Shahrukh Chishti',
12
- version="0.1.1",
12
+ version="0.1.2",
13
13
  python_requires=">=3.11",
14
14
  packages=find_packages(),
15
15
  install_requires=load_requirements(root / "requirements.txt"),
@@ -1,6 +0,0 @@
1
- # plotly-lite
2
- lite version wrapper on plotly
3
- * quick utilization
4
- * compare
5
- * heatmap
6
- * trajectories
@@ -1,126 +0,0 @@
1
- import plotly.offline as py
2
- import plotly.graph_objs as go
3
- import matplotlib.pyplot as plt
4
- import time
5
-
6
- def render(fig,title,size,html,export):
7
- fig.update_layout(font={'size':30})
8
- fig.update_layout(margin_t=10,margin_r=10)
9
- fig.update_layout(legend=dict(yanchor="top",y=0.99,xanchor="right",x=0.99,bgcolor="rgba(0,0,0,.05)"))
10
- if size:
11
- height,width = size
12
- fig.update_layout(width=width,height=height)
13
- if export:
14
- fig.write_image('./'+title+'.'+export)
15
- time.sleep(2)
16
- fig.write_image('./'+title+'.'+export)
17
- fig.update_layout(title=title)
18
- fig.update_layout(margin_t=100)
19
- if html:
20
- fig.write_html('./'+title+'.html')
21
- else :
22
- py.iplot(fig)
23
-
24
- def plotBox(plot,title=None,x_label=None,y_label=None,size=None,html=False,export=None,ylimit=None):
25
- fig = go.Figure()
26
- for name,dist in plot.items():
27
- fig.add_trace(go.Box(y=dist,name=name))
28
- fig.update_layout(xaxis_title=x_label,yaxis_title=y_label)
29
- fig.update_layout(showlegend=False)
30
- fig.update_layout(yaxis_range=ylimit)
31
-
32
- render(fig,title,size,html,export)
33
-
34
- def plotCombine(plot,title=None,x_label=None,y_label=None,mode='lines',width=5,size=None,html=False,export=None,legend=True):
35
- fig = go.Figure()
36
- for name,(x,y) in plot.items():
37
- fig.add_trace(go.Scatter(x=x,y=y,name=name,mode=mode,line={'width':width},marker={'size':width}))
38
- fig.update_layout(xaxis_title=x_label,yaxis_title=y_label)
39
- fig.update_layout(showlegend=legend)
40
- render(fig,title,size,html,export)
41
-
42
- def plotScatter(x,plot,title=None,x_label=None,y_label=None,size=None,dot_size=1,html=False,export=None,legend=True):
43
- fig = go.Figure()
44
- for name,values in plot.items():
45
- fig.add_trace(go.Scatter(x=x,y=values,name=name,mode='markers',marker={'size':dot_size}))
46
- fig.update_layout(xaxis_title=x_label,yaxis_title=y_label)
47
- fig.update_layout(showlegend=legend)
48
- render(fig,title,size,html,export)
49
-
50
- def plotCompare(x,plot,title=None,x_label=None,y_label=None,width=5,size=None,html=False,export=None,legend=True):
51
- fig = go.Figure()
52
- for name,values in plot.items():
53
- fig.add_trace(go.Scatter(x=x,y=values,name=name,line={'width':width}))
54
- fig.update_layout(xaxis_title=x_label,yaxis_title=y_label)
55
- fig.update_layout(showlegend=legend)
56
- render(fig,title,size,html,export)
57
-
58
- def plotMap(z,x,y,title=None,xaxis=None,yaxis=None,size=None,html=False,export=None,legend=True,log=False):
59
- fig = go.Figure()
60
- heatmap = go.Heatmap(z=z,y=y,x=x)
61
- fig.add_trace(heatmap)
62
- fig.update_layout(showlegend=legend)
63
- fig.update_traces(showscale=legend)
64
- fig.update_layout(coloraxis_showscale=legend)
65
- fig.update_layout(xaxis_title=xaxis,yaxis_title=yaxis)
66
- if log:
67
- fig.update_xaxes(type="log")
68
- fig.update_yaxes(type="log")
69
-
70
- render(fig,title,size,html,export)
71
-
72
- def plotHeatmap(z,x,y,title=None,xaxis=None,yaxis=None,size=None,html=False,export=None,ncontours=10,legend=True,log=False):
73
- fig = go.Figure()
74
- start=z.min(); end=z.max()
75
- contours = dict(start=start,end=end,size=(end-start)/ncontours)
76
- heatmap = go.Contour(z=z,y=y,x=x,contours_coloring='heatmap',contours=contours)
77
- fig.add_trace(heatmap)
78
- fig.update_layout(showlegend=legend)
79
- fig.update_traces(showscale=legend)
80
- fig.update_layout(coloraxis_showscale=legend)
81
- fig.update_layout(xaxis_title=xaxis,yaxis_title=yaxis)
82
- if log:
83
- fig.update_xaxes(type="log")
84
- fig.update_yaxes(type="log")
85
-
86
- render(fig,title,size,html,export)
87
-
88
- def plotTrajectory(evo,plot,title=None,x_label=None,y_label=None,size=None,html=False,export=None,legend=False):
89
- fig = go.Figure()
90
- evo = evo/max(evo)*15
91
- for name,path in plot.items():
92
- fig.add_trace(go.Scatter(x=path[:,0],y=path[:,1],name=name,mode='lines+markers',
93
- marker={'size':evo},line={'width':5}))
94
- fig.update_layout(xaxis_title=x_label,yaxis_title=y_label)
95
- fig.update_layout(showlegend=legend)
96
- render(fig,title,size,html,export)
97
-
98
- def plotOptimization(z,x,y,paths,title=None,xaxis=None,yaxis=None,size=None,html=False,export=None,legend=False,log=False):
99
- fig = go.Figure()
100
- heatmap = go.Contour(z=z,y=y,x=x,name='loss',contours_coloring='heatmap')
101
- fig.add_trace(heatmap)
102
- fig.update_layout(xaxis_title=xaxis,yaxis_title=yaxis)
103
- for name,path in paths.items():
104
- evo = [x * 15 / len(path) for x in range(len(path))]
105
- fig.add_trace(go.Scatter(x=path[:,0],y=path[:,1],name=name,mode='lines+markers',marker={'size':evo},line={'width':3}))
106
- fig.update_layout(showlegend=legend)
107
- if log:
108
- fig.update_xaxes(type="log")
109
- fig.update_yaxes(type="log")
110
- render(fig,title,size,html,export)
111
-
112
- # graph plots
113
-
114
- def viewPCA(X,index,size=(8,6),title=None,x=None,y=None):
115
- from sklearn.decomposition import PCA
116
- pca = PCA(n_components=2)
117
- X_pca = pca.fit_transform(X)
118
-
119
- # Visualize in 2D
120
- plt.figure(figsize=size)
121
- plt.scatter(X_pca[:, 0], X_pca[:, 1], c=index, cmap='viridis')
122
- plt.xlabel(x)
123
- plt.ylabel(y)
124
- plt.title(title)
125
- plt.colorbar(label='index')
126
- plt.show()
File without changes
File without changes
File without changes