Skip to content

Conversation

@xylar
Copy link
Collaborator

@xylar xylar commented Apr 7, 2020

Cells below maxLevelCell are no longer included.

Cells below maxLevelCell are no longer included.
@xylar
Copy link
Collaborator Author

xylar commented Apr 7, 2020

I also switched the text with max/min in the plot to a monospace font so the columns align better.

@xylar
Copy link
Collaborator Author

xylar commented Apr 7, 2020

initial_state

Comment on lines 10 to +13
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Usually, you need to switch to the Agg backend before importing plt. I guess that isn't required in the most recent matplotlib but it's still safer to do it in this order. PEP8 will complain about imports not being at the top but it is necessary in this case.

plt.subplot(3, 3, 4)
varName = 'temperature'
var = ncfile.variables[varName]
plt.hist(np.ndarray.flatten(var[:]), bins=100, log=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The mask takes care of of flattening the array in this case but a more efficient way of flattening a typical numpy array is to call its ravel method: var[:].ravel()

Comment on lines 67 to 68
txt = txt + ' {:9.2e}'.format(np.min(var)) + \
' {:9.2e}'.format(np.max(var)) + ' ' + varName + '\n'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't have the energy to change all the formatting, but I would not use str addition like this. For example, here, I would do:

Suggested change
txt = txt + ' {:9.2e}'.format(np.min(var)) + \
' {:9.2e}'.format(np.max(var)) + ' ' + varName + '\n'
txt = '{}{:9.2e} {:9.2e} {}\n'.format(txt, np.amin(var), np.amax(var), varName)

I think amin and amax are considered to be the better than the aliases min and max because it clarifies that you want the min/max over the array vs. minimum and maximum, which give the element-wise min/max between two arrays.

Comment on lines +118 to +123
font = FontProperties()
font.set_family('monospace')
font.set_size(12)
print(txt)
plt.subplot(3, 3, 1)
plt.text(0, 1, txt, fontsize=12, verticalalignment='top')
plt.text(0, 1, txt, verticalalignment='top', fontproperties=font)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Apparently, this is how you change fonts. Never had to do this before.

@mark-petersen
Copy link
Contributor

@xylar you are too good! Thanks for the changes. I appreciate the python improvements as well!

@mark-petersen mark-petersen merged commit ab0cb8e into MPAS-Dev:ocean/develop Apr 7, 2020
@xylar xylar deleted the ocean/fix_plot_init branch April 7, 2020 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants