pyvlasiator 0.1.2__tar.gz → 0.1.3__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.

Potentially problematic release.


This version of pyvlasiator might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyvlasiator
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Python utilities for processing Vlasiator data
5
5
  Author: Hongyang Zhou
6
6
  Author-email: hyzhou@umich.edu
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pyvlasiator"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  description = "Python utilities for processing Vlasiator data"
5
5
  authors = ["Hongyang Zhou <hyzhou@umich.edu>"]
6
6
  readme = "README.md"
@@ -6,6 +6,7 @@ This provides supports for plotting VLSV data via Matplotlib.
6
6
 
7
7
  from pyvlasiator.plot.plot import (
8
8
  plot,
9
+ scatter,
9
10
  pcolormesh,
10
11
  contour,
11
12
  contourf,
@@ -96,24 +96,91 @@ def plot(
96
96
  >>> axes = vlsv_file.plot("helium/vg_v", ax=my_axes) # Plot velocity on an existing axes
97
97
  """
98
98
 
99
- import matplotlib.pyplot as plt
99
+ fig, ax = set_figure(ax, figsize, **kwargs)
100
100
 
101
- fig = kwargs.pop(
102
- "figure", plt.gcf() if plt.get_fignums() else plt.figure(figsize=figsize)
101
+ return _plot1d(
102
+ self,
103
+ ax.plot,
104
+ var=var,
105
+ **kwargs,
103
106
  )
104
- if ax is None:
105
- ax = fig.gca()
106
107
 
107
- if not self.has_variable(var):
108
- raise ValueError(f"Variable {var} not found in the file")
109
108
 
110
- x = np.linspace(self.coordmin[0], self.coordmax[0], self.ncells[0])
109
+ def scatter(
110
+ self: Vlsv,
111
+ var: str = "",
112
+ ax=None,
113
+ figsize: tuple[float, float] | None = None,
114
+ **kwargs,
115
+ ) -> matplotlib.collections.PathCollection:
116
+ """
117
+ Plots 1D VLSV data as scattered points.
118
+
119
+ Parameters
120
+ ----------
121
+ var : str
122
+ Name of the variable to plot from the VLSV file.
123
+ ax : matplotlib.axes._axes.Axes, optional
124
+ Axes object to plot on. If not provided, a new figure and axes will be created.
125
+ figsize : tuple[float, float], optional
126
+ Size of the figure in inches (width, height). Only used if a new
127
+ figure is created.
128
+ **kwargs
129
+ Additional keyword arguments passed to Matplotlib's `plot` function.
130
+
131
+ Returns
132
+ -------
133
+ matplotlib.collections.PathCollection
134
+
135
+ Raises
136
+ ------
137
+ ValueError
138
+ If the specified variable is not found in the VLSV file.
139
+
140
+ Examples
141
+ --------
142
+ >>> vlsv_file = Vlsv("my_vlsv_file.vlsv")
143
+ >>> axes = vlsv_file.scatter("proton/vg_rho") # Plot density on a new figure
144
+ """
145
+
146
+ fig, ax = set_figure(ax, figsize, **kwargs)
111
147
 
112
- data = self.read_variable(var)
113
- axes = ax.plot(x, data, **kwargs)
148
+ return _plot1d(
149
+ self,
150
+ ax.scatter,
151
+ var=var,
152
+ **kwargs,
153
+ )
114
154
 
115
- return axes
116
155
 
156
+ def _plot1d(
157
+ meta: Vlsv,
158
+ plot_func: Callable,
159
+ var: str = "",
160
+ **kwargs,
161
+ ):
162
+ """
163
+ Plot 1d data with `plot_func`.
164
+
165
+ Parameters
166
+ ----------
167
+ var : str
168
+ Variable name from the VLSV file.
169
+
170
+ Returns
171
+ -------
172
+
173
+ """
174
+
175
+ if not meta.has_variable(var):
176
+ raise ValueError(f"Variable {var} not found in the file")
177
+
178
+ x = np.linspace(meta.coordmin[0], meta.coordmax[0], meta.ncells[0])
179
+ y = meta.read_variable(var)
180
+
181
+ c = plot_func(x, y, **kwargs)
182
+
183
+ return c
117
184
 
118
185
  def pcolormesh(
119
186
  self: Vlsv,
@@ -839,13 +906,13 @@ def configure_plot(
839
906
  cb.ax.set_ylabel(colorbar_title)
840
907
  cb.ax.tick_params(direction="in")
841
908
 
842
- # Set plot title and labels
909
+ # Set title and labels
843
910
  ax.set_title(title, fontweight="bold")
844
911
  ax.set_xlabel(x_label)
845
912
  ax.set_ylabel(y_label)
846
913
  ax.set_aspect("equal")
847
914
 
848
- # Style plot borders and ticks
915
+ # Style borders and ticks
849
916
  for spine in ax.spines.values():
850
917
  spine.set_linewidth(2.0)
851
918
  ax.tick_params(axis="both", which="major", width=2.0, length=3)
@@ -1110,6 +1177,7 @@ def prep_vdf(
1110
1177
 
1111
1178
  # Append plotting functions
1112
1179
  Vlsv.plot = plot
1180
+ Vlsv.scatter = scatter
1113
1181
  Vlsv.pcolormesh = pcolormesh
1114
1182
  Vlsv.contourf = contourf
1115
1183
  Vlsv.contour = contour
File without changes
File without changes