Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow more than 2 colormaps again #493

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

Merged
Kully merged 5 commits into master from trisurf_plus_2_colormap
Jun 3, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added legibility to mapface2color func et PEP8
  • Loading branch information
Kully committed Jun 2, 2016
commit c89cda10a5dc66d7d9bc783c8e55e78953d20b71
37 changes: 18 additions & 19 deletions plotly/tools.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1518,33 +1518,32 @@ def _map_face2color(face, colormap, vmin, vmax):
"and vmax. The vmin value cannot be "
"bigger than or equal to the value "
"of vmax.")
# find the normalized distance t of a triangle face between vmin and
#vmax where the distance is normalized between 0 and 1
t = (face - vmin) / float((vmax - vmin))

if len(colormap) <= 1:
t_color = colormap[0]
color = FigureFactory._convert_to_RGB_255(t_color)
color = FigureFactory._label_rgb(color)

if len(colormap) == 1:
# color each triangle face with the same color in colormap
face_color = colormap[0]
face_color = FigureFactory._convert_to_RGB_255(face_color)
face_color = FigureFactory._label_rgb(face_color)
else:
# account for colormaps with more than one color
incr = 1./(len(colormap) - 1)
low_color_index = int(t/incr)
# find the normalized distance t of a triangle face between vmin
# and vmax where the distance is normalized between 0 and 1
t = (face - vmin) / float((vmax - vmin))
low_color_index = int(t / (1./(len(colormap) - 1)))
Copy link
Contributor

@theengineear theengineear Jun 2, 2016

Choose a reason for hiding this comment

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

🐄 Sorry if I'm just missing something, but isn't:

1 / ( 1 / val ) = val

And isn't iterable[len(iterable) - 1] = iterable[-1]

So

iterable[1 / ( 1 / (len(iterable) - 1)] = iterable[-1]

I feel like iterable[-1] is more understandable than iterable[1 / ( 1 / (len(iterable) - 1)]

This means that you don't need to calculate low_color_index = int(t / (1./(len(colormap) - 1))) until you're inside the else statement, which also improves readability here.


if t == 1:
t_color = colormap[low_color_index]
color = FigureFactory._convert_to_RGB_255(t_color)
color = FigureFactory._label_rgb(color)
face_color = colormap[low_color_index]
face_color = FigureFactory._convert_to_RGB_255(face_color)
face_color = FigureFactory._label_rgb(face_color)

else:
t_color = FigureFactory._find_intermediate_color(
face_color = FigureFactory._find_intermediate_color(
colormap[low_color_index],
colormap[low_color_index + 1],
(t - low_color_index * incr) / incr)
color = FigureFactory._convert_to_RGB_255(t_color)
color = FigureFactory._label_rgb(color)
t * (len(colormap) - 1) - low_color_index)
face_color = FigureFactory._convert_to_RGB_255(face_color)
face_color = FigureFactory._label_rgb(face_color)

return color
return face_color
Copy link
Contributor

@theengineear theengineear Jun 2, 2016

Choose a reason for hiding this comment

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

💥 so much more readable! thanks!


@staticmethod
def _trisurf(x, y, z, simplices, colormap=None, color_func=None,
Expand Down

AltStyle によって変換されたページ (->オリジナル) /