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

Fix plotter module (#167) #172

Merged

Conversation

jayspeidell
Copy link
Contributor

Description

Bug fix: Added 'z-axis' to formatters/Designer attribute 'labels' to prevent index out of range error when plotting in 3D. Also added a third dimension to 'limits' for the same reason.

New feature: I added a colormaps property to the Designer class in formatters.py to allow the user to choose whichever one they want. It uses the same style as other properties of the class, and the module imports matplotlib.cm to validate both types of colormaps in matplotlib. I edited plotters/plot_countour to initialize a Designer object with a default colormap if none is provided. I've tested with every category of colormap as well as custom colormaps and verified that it is working as intended.

Default parameter change: Mesher.delta from 0.001 to 0.1. This makes it safe to run many of the functions on an average computer. With 0.001, the mesher object grows very quickly.

Related Issue

Fix plotter module (#167)

Motivation and Context

Adding a colormap attribute to Designer made easier to verify the functions. I implemented because it enabled me to use discreet colormaps.

How Has This Been Tested?

Then I used flask8 and black. I restricted flask8 and black testing to the files that I edited in each commit. I also ran py.test.

I tested Designer on all types of matplotlib colormaps. I didn't add a test to do this automatically, but it will return a TypeError if it's not a valid colormap. Does it need a test?

Screenshots (if appropriate):

sphere_example

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

1. The designer class in formatters.py is used for 3D graphing, but the default label list attribute only includes two axes. This causes an index out of range error. I added "z-axis".

2. The delta attribute of the Mesher class in formatters.py is 0.001. This is too detailed and can lead to mesher objects that are large enough to cause memory errors. I changed it to 0.1.

3. The use can't choose a colormap when graphing, so I added a colormaps property to the Designer class in formatters.py to allow the user to choose whichever one they want. It uses the same style as other properties of the class, and the module imports matplotlib.cm to validate both types of colormaps in matplotlib. I edited plotters/plot_countour to initialize a Designer object with a default colormap if none is provided. I've tested with every category of colormap as well as custom colormaps and verified that it is working as intended.
Default value for attribute limits in Designer class only has two dimensions. Added a third.
@ljvmiranda921 ljvmiranda921 self-assigned this Jul 18, 2018
@ljvmiranda921 ljvmiranda921 self-requested a review July 18, 2018 03:28
@ljvmiranda921
Copy link
Owner

ljvmiranda921 commented Jul 18, 2018

Bug fix: Added 'z-axis' to formatters/Designer attribute 'labels' to prevent index out of range error when plotting in 3D. Also added a third dimension to 'limits' for the same reason.

Understood.

New feature: I added a colormaps property to the Designer class in formatters.py to allow the user to choose whichever one they want.

This is good! I guess it's better to add flexibility with respect to colormaps. 👍

Default parameter change: Mesher.delta from 0.001 to 0.1. This makes it safe to run many of the functions on an average computer. With 0.001, the mesher object grows very quickly.

Copy that.

Let me do the review in a while 👍

@ljvmiranda921 ljvmiranda921 added bug Bugs, bug fixes, etc. enhancement Feature requests v0.3.0 unit tests Test-related changes labels Jul 18, 2018
@@ -10,6 +10,7 @@
import numpy as np
from attr import attrs, attrib
from attr.validators import instance_of
from matplotlib import cm

Copy link
Owner

Choose a reason for hiding this comment

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

I think the best way to validate the colormaps is to check if they are instances of the matplotlib.colors.Colormap class. Both ListedColormap (the type of cm.viridis) and LinearSegmentedColormap (the type of cm.binary) are subclasses of Colormap.

So my suggestion is:

from matplotlib import cm, colors

class Designer(object):
    colormap = attrib(
        validator=instance_of(colors.Colormap),
        default=cm.viridis,
     )

Can you confirm if this works? 😄
If this works, I think there's no need to write tests for all colormaps since we have a validator that gives out an error whenever we enter a non-Colormap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense! I had been trying to validate colors.Colormap with type(), but that's redundant with attrib and messes things up.

)
colormap = attrib(
validator=instance_of((type(cm.viridis), type(cm.binary))),
default=cm.viridis,
)
Copy link
Owner

Choose a reason for hiding this comment

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

This line of code is related to my comment above. I think it's better to check against matplotlib.colors.Colormap because it is the base class for whatever type(cm.viridis) and type(cm.binary) is

Have the Designer class validate for the base class matplotlib.colors.Colormap instead of the individual types of colormaps.
@ljvmiranda921
Copy link
Owner

LGTM! Will merge in a while 👍

@ljvmiranda921 ljvmiranda921 merged commit 966516b into ljvmiranda921:development Jul 18, 2018
@ljvmiranda921
Copy link
Owner

Merged. Thank you so much @jayspeidell ! I appreciate this contribution! You're correct, I realized that we should decrease the resolution in the mesh to accommodate other machines. I also liked the fact that you opened-up flexibility for the users in choosing their colormaps. Good job! 🎉

Thanks a lot for this wonderful PR. I hope you enjoyed despite the minor hassle of separating PRs the last time hehe 💯 Aaron will take over the review of your other PR, we hope to see you again!

@jayspeidell
Copy link
Contributor Author

@ljvmiranda921 Awesome, thanks! I appreciate the opportunity to learn the process.

@ljvmiranda921 ljvmiranda921 mentioned this pull request Aug 8, 2018
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs, bug fixes, etc. enhancement Feature requests unit tests Test-related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants