Skip to content

Annotated heatmap #359

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
merged 12 commits into from
Nov 26, 2015
Merged

Annotated heatmap #359

merged 12 commits into from
Nov 26, 2015

Conversation

cldougl
Copy link
Member

@cldougl cldougl commented Nov 25, 2015

  • add annotated heatmaps and tables to FigureFactory

- add FF option for annotated heatmaps with logical text colouring
- users can supply a matrix of text for annotations otherwise the value
from the z matrix is used
- add FF option to create a table (defaults to striped table)
- input options are a z matrix or a pandas data frame
- option for user to supply table colours and font colours
- add validation functions and tests for annotated_heatmap and tables
- add docstrings for all functions
- fix annotated_heatmap annotations so the font color logic is followed
when a text matrix is supplied.
@chriddyp
Copy link
Member

@cldougl - ready for review?

@cldougl
Copy link
Member Author

cldougl commented Nov 25, 2015

@chriddyp the code is but I'm making a notebook of examples for you guys now

- doc examples
- add hover text option for annotated heatmaps
@cldougl
Copy link
Member Author

cldougl commented Nov 25, 2015

@chriddyp @theengineear @etpinard
Annotated Heatmaps and Tables are ready for review! Here are a few use examples: http://nbviewer.ipython.org/gist/cldougl/d746349aa58ab1eca55c


@staticmethod
def create_table(text, colorscale=[[0, '#66b2ff'], [.5, '#e6e6e6'],
[1, '#ffffff']], fontcolor=['#000000'],
Copy link
Member Author

Choose a reason for hiding this comment

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

@chriddyp I thought these colors looked pretty good for the default table colors but I'm super open to other suggestions

- changed `text` to `annotation_text` and `table_text` so the `text`
argument can still be used for hover
- cleaned up arg names and order
@chriddyp
Copy link
Member

super sweet @cldougl :):))
A few issues/thoughts:

  • numpy error:
>>> iplot(FF.create_annotated_heatmap(np.random.randn(20, 20)))
----> 1 iplot(FF.create_annotated_heatmap(np.random.randn(20, 20)))

/Users/chriddyp/Repos/python-api/plotly/tools.py in create_annotated_heatmap(z, x, y, text, hover_text, fontcolor, showscale, **kwargs)
   2605         FigureFactory._validate_annotated_heatmap(z, text)
   2606         annotations = _AnnotatedHeatmap(z, x, y, text, fontcolor,
-> 2607                                         **kwargs).make_annotations()
   2608 
   2609         if x or y:

/Users/chriddyp/Repos/python-api/plotly/tools.py in make_annotations(self)
   3775                         yref='y1',
   3776                         font=dict(color=min_text_color if val <
-> 3777                                   (max(max(self.z))-min(min(self.z))) / 2
   3778                                   else max_text_color),
   3779                         showarrow=False))

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  • Is it safe to shrink down the margins on the tables since they don't have axes labels? It'll look nice n flush in ipython notebooks that way (looks like you'll need to do some adjustments on the rows, though)
    image

@cldougl
Copy link
Member Author

cldougl commented Nov 25, 2015

ok @chriddyp @theengineear sorry for that false alarm earlier- it's ready now!
http://nbviewer.ipython.org/gist/cldougl/45285a3b01e81023f7ae

@cldougl
Copy link
Member Author

cldougl commented Nov 25, 2015

@chriddyp

  • no problems for the margins (I'll edit that and lower the row constant)
  • wasn't testing with numpy :( shouldn't be a big deal to incorporate- I'll fix that now and add a test

@chriddyp
Copy link
Member

It's sweet that dataframes just work!

from datetime import datetime
import pandas.io.data as web

df = web.DataReader("aapl", 'yahoo', datetime(2007, 10, 1), datetime(2009, 4, 1))
iplot(FF.create_table(df))

image

- remove margins from tables
@chriddyp
Copy link
Member

I like the default table colors, but @jackparmer or @delekru might have an opinion
image

@chriddyp
Copy link
Member

Could we split the first example in Tables into two example? One that is just text, and the next that includes the colorscale and fontcolor updates?
image

@cldougl
Copy link
Member Author

cldougl commented Nov 25, 2015

yep np!

@delekru
Copy link

delekru commented Nov 25, 2015

small adjustment suggestions:
suggestions

Just because the light blue on black looks funny to me.

@jackparmer
Copy link
Contributor

Nice! +1 on Derek's colors. Looks like Fornightly Thoughts
http://www.goldmansachs.com/s/esg-impact/assets/downloads/Fortnightly_Thoughts_The_changing_parts_of_Europe.pdf

On Wed, Nov 25, 2015 at 2:34 PM, derek lu notifications@github.com wrote:

small adjustment suggestions:
[image: suggestions]
https://cloud.githubusercontent.com/assets/11370069/11407511/4f8a5714-9381-11e5-9b4c-8005d36d8b77.png

Just because the light blue on black looks funny to me.


Reply to this email directly or view it on GitHub
#359 (comment).

@cldougl
Copy link
Member Author

cldougl commented Nov 25, 2015

thanks @delekru ! I like defaulting to a darker header color w/ white font and using black in the table

@jackparmer
Copy link
Contributor

Can we have an additional example with tables with links and
LaTeX?

On Wed, Nov 25, 2015 at 2:41 PM, Chelsea notifications@github.com wrote:

thanks @delekru https://github.com/delekru ! I like defaulting to a
darker header color w/ white font and using black in the table


Reply to this email directly or view it on GitHub
#359 (comment).

@cldougl
Copy link
Member Author

cldougl commented Nov 25, 2015

@jackparmer yep 👍

- add numpy compatibility
- change default table colors
- fix for average calculation happening in `make_annotations`
- update tests to reflect changes
- break up example 1 in table docstring

To-Do
[ ] update table test to reflect new colours
[ ] update table fontcolor logic so `if index` the column font color
matches header font color
@jackparmer
Copy link
Contributor

Ooooohhh, also a subplot of a chart plus a table side-by-side. That one
comes up a lot.

On Wed, Nov 25, 2015 at 3:03 PM, Chelsea notifications@github.com wrote:

@jackparmer https://github.com/jackparmer yep [image: 👍]


Reply to this email directly or view it on GitHub
#359 (comment).


def test_unequal_z_text_size(self):

# check: PlotlyError if z and text are not the same dimmensions
Copy link
Contributor

Choose a reason for hiding this comment

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

🐐 dimension

['Canada', 2010, 34000000]]

table=FF.create_table(text)
py.iplot(table)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the table name makes sense here, fwiw 😄

@theengineear
Copy link
Contributor

@cldougl Sweet, looking good!! This is going to be awesome!

My biggest concern is the commented out table test. I'd like that to be in place and passing before this rolls on through. Mind giving me a quick poke after some edits are in?

- add validation for `x` and `y` in `annotated_heatmap`
- correct/improve docstrings
- uncomment and update table test
- add test for `x` and `y` `annotated_heatmap` validation
- (also fixed a pep8 mistake from review)
@cldougl
Copy link
Member Author

cldougl commented Nov 26, 2015

@theengineear thanks for the review!! all updated now

hex_total_length = len(value)
rgb_section_length = hex_total_length // 3
return tuple(int(value[i:i + rgb_section_length], 16)
for i in range(0, hex_total_length, rgb_section_length))
Copy link
Contributor

Choose a reason for hiding this comment

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

:) thx!

@theengineear
Copy link
Contributor

Aw jeez. Throttling issues with testing. Let me throw our test users on to some subscriptions.

@theengineear
Copy link
Contributor

💃 after tests 🎏

@theengineear
Copy link
Contributor

Aight, re-running your tests.

cldougl and others added 3 commits November 26, 2015 15:58
- `range()` was resulting in an `obj` in python3 where a `list` was
needed
- added annotated heatmaps and tables to FigureFactory
cldougl added a commit that referenced this pull request Nov 26, 2015
@cldougl cldougl merged commit bb29e74 into master Nov 26, 2015
@cldougl cldougl deleted the annotated_heatmap branch April 4, 2016 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants