Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored plot.hist1d to permit weights kwarg. #333

Merged
merged 1 commit into from
Jun 15, 2020
Merged

Refactored plot.hist1d to permit weights kwarg. #333

merged 1 commit into from
Jun 15, 2020

Conversation

JS3xton
Copy link
Contributor

@JS3xton JS3xton commented May 12, 2020

plot.hist1d() called with the weights parameter fails:

>>> FlowCal.plot.hist1d(np.array([1,2,3,1,2,1]), weights=[1,2,1,2,2,1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\sexto\Downloads\FlowCal\FlowCal\plot.py", line 971, in hist1d
    n, edges, patches = plt.hist(y,
TypeError: hist() got multiple values for keyword argument 'weights'

I refactored plot.hist1d() to more precisely specify arguments to plt.hist(). Closes #255.

All unit tests pass in Python 3.8 + Anaconda 2020.02 and Python 2.7 + Anaconda 4.4.0.

After the change, the error shown above no longer occurs. > python -m FlowCal.excel_ui -v -p -i ./examples/experiment.xlsx also executes without error in both Python 3.8 + Anaconda 2020.02 and Python 2.7 + Anaconda 4.4.0.

@castillohair
Copy link
Collaborator

Can you provide examples of your code producing a few plots as before, and at least one plot demonstrating the new ability to specify weights?

@JS3xton
Copy link
Contributor Author

JS3xton commented Jun 14, 2020

develop (9cd83ef) hist1d-weights (ed1af38)
hist1d(d)
hist1d(d, normed_height=True)
hist1d(d, normed_area=True)
hist1d(d, weights=weights) TypeError

Source code (inspired by the hist1d tutorial):

import numpy as np
import matplotlib.pyplot as plt
import FlowCal

d = FlowCal.io.FCSData('./FCFiles/Data002.fcs')
d = FlowCal.transform.to_rfi(d)
bins = np.logspace(0,4,100+1)
weights = np.ones(d.shape[0])
weights /= float(d.shape[0])
kwargs = {'data_list' : d,
          'channel'   : 'FL1',
          'bins'      : bins,
          'xlim'      : (1e0,1e4)}

FlowCal.plot.hist1d(**kwargs, savefig='1.png')
FlowCal.plot.hist1d(**kwargs, savefig='2.png', normed_height=True)
FlowCal.plot.hist1d(**kwargs, savefig='3.png', normed_area=True)
FlowCal.plot.hist1d(**kwargs, savefig='4.png', weights=weights)

@castillohair castillohair merged commit 63d8eeb into taborlab:develop Jun 15, 2020
@JS3xton JS3xton deleted the hist1d-weights branch June 15, 2020 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants