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

Support iris.plot.hist and iris.quickplot.hist #3330

Closed
bjlittle opened this issue Jun 9, 2019 · 3 comments · Fixed by #5189
Closed

Support iris.plot.hist and iris.quickplot.hist #3330

bjlittle opened this issue Jun 9, 2019 · 3 comments · Fixed by #5189

Comments

@bjlittle
Copy link
Member

bjlittle commented Jun 9, 2019

There have been user requests for the iris convenience plotting capabilities to be extended such that a cube can be passed to iris.plot.hist and/or iris.quickplot.hist to generate histogram plots by using matplotlib.pyplot.hist

@BenMGeo do you have some example use cases to support his issue?

@bjlittle bjlittle changed the title Support iris.plot.hist and iris.quickplot.jist Support iris.plot.hist and iris.quickplot.hist Jun 9, 2019
@pelson
Copy link
Member

pelson commented Apr 17, 2021

Hi from the other side! I found myself needing something like this recently... here is my use case:

I have all of the observed temperatures for a given site, I take only those of a given month and hour, and want to see the distribution of temperatures for that hour in that month. I then plan to fit that distribution to a statistical model and use it to calculate the climatological probability of a given temperature at a given time in a given month (pretty useful!).

@pelson
Copy link
Member

pelson commented Apr 17, 2021

For my own record, I hacked something together:

n_bins = 20
counts, bins = np.histogram(temp.data, np.linspace(temp.data.min(), temp.data.max(), n_bins + 1))
bounds = np.vstack([bins[:-1], bins[1:]]).T

frequency_cube = iris.cube.Cube(
    data=counts, long_name='temperature_frequency', dim_coords_and_dims=(
        (iris.coords.DimCoord(points=bounds.mean(axis=1), bounds=bounds, long_name='temperature'), 0),
    ),
)

And then I did a bar plot of the cube with:

# Plot the data as a histogram.
bar_widths = np.diff(frequency_cube.coord('temperature').bounds, axis=1)[:, 0]
plt.bar(frequency_cube.coord('temperature').points, frequency_cube.data, width=bar_widths)

Truth be told, this is probably a good use case for something like pandas. The only way I could convince myself that it would be a good thing for Iris to have is if we needed multi-dimensional equivalents. For example, imagine having all sites, and all months, and all hours as 3 distinct dimensions, and wanted to do the same analysis and resulting in a multidimensional cube.

@trexfeathers
Copy link
Contributor

Truth be told, this is probably a good use case for something like pandas. The only way I could convince myself that it would be a good thing for Iris to have is if we needed multi-dimensional equivalents. For example, imagine having all sites, and all months, and all hours as 3 distinct dimensions, and wanted to do the same analysis and resulting in a multidimensional cube.

@pelson we've recently enhanced iris.pandas.as_data_frame(), so that it can handle the n-dimensional case. Would that suit future use cases for you?

@trexfeathers trexfeathers moved this from 📋 Backlog to 🔖 Ready in ESMValTool Feb 22, 2023
@lbdreyer lbdreyer moved this from 🔖 Ready to 🏗 In progress in ESMValTool Mar 7, 2023
@lbdreyer lbdreyer moved this from 🏗 In progress to 👀 In review in ESMValTool Mar 9, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in ESMValTool Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants