Skip to content

Conversation

@sam-grant
Copy link
Contributor

@sam-grant sam-grant commented Jan 29, 2025

Tidied up the methods and added the functionality to pass user defined axes to the plotting functions for improved flexibility.

I also added docstrings to the functions in the Print and Plot classes, which can be accessed as follows:

>>> import pyplot as plot
>>> plotter = plot.Plot()
>>> help(plotter.Plot1D)

Help on method Plot1D in module pyplot:

Plot1D(array, nbins=100, xmin=-1.0, xmax=1.0, weights=None, title=None, xlabel=None, ylabel=None, col='black', leg_pos='best', out_path=None, dpi=300, log_x=False, log_y=False, under_over=False, stat_box=True, stat_box_errors=False, error_bars=False, ax=None, show=True) method of pyplot.Plot instance
    Create a 1D histogram from an array of values.

    Args:
      array (np.ndarray): Input data array
      weights (np.ndarray, optional): Weights for each value
      nbins (int, optional): Number of bins. Defaults to 100
      xmin (float, optional): Minimum x-axis value. Defaults to -1.0
      xmax (float, optional): Maximum x-axis value. Defaults to 1.0
      title (str, optional): Plot title
      xlabel (str, optional): X-axis label
      ylabel (str, optional): Y-axis label
      col (str, optional): Histogram color. Defaults to 'black'
      leg_pos (str, optional): Legend position. Defaults to 'best'
      out_path (str, optional): Path to save the plot
      dpi (int, optional): DPI for saved plot. Defaults to 300
      log_x (bool, optional): Use log scale for x-axis. Defaults to False
      log_y (bool, optional): Use log scale for y-axis. Defaults to False
      under_over (bool, optional): Show overflow/underflow stats. Defaults to False
      stat_box (bool, optional): Show statistics box. Defaults to True
      stat_box_errors (bool, optional): Show errors in stats box. Defaults to False
      error_bars (bool, optional): Show error bars on bins. Defaults to False
      ax (plt.Axes, optional): External custom axes
      show (bool, optional): Display the plot, defaults to True

    Raises:
      ValueError: If array is empty or None

Finally, I updated the example script example_plotting.py.

@sophiemiddleton sophiemiddleton self-requested a review January 30, 2025 14:11
Copy link
Collaborator

@sophiemiddleton sophiemiddleton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Sam, I'm going to open this asa PR on the main branch since it looks like we've made some good progress

@sophiemiddleton sophiemiddleton merged commit 723718a into Mu2e:pyutils-dev Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants