Skip to content

ENH/VIS: Plotting DataFrame/Series with matplotlib.table #6661

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 1 commit into from
Apr 7, 2014

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Mar 18, 2014

closes #4803

Related to #4803, I prepared some codes to add a matplotlib.Table to DataFrame and Series plot using table keyword. table can take followings as an input:

  • False: Do nothing (default).
  • True: Draw a table using the data called plot method. Data will be transposed to meet the matplotlib's default layout.
  • DataFrame or Series: Draw matplotlib.table using the passed data. The data will be drawn as displayed in print method (not transposed automatically).

Also, helper function pandas.tools.plotting.table is added to create a table from DataFrame and Series, and add it to the matplotlib.Axes.

Example:

fig, axes = plt.subplots(1, 3, figsize=(14, 4))
plt.subplots_adjust(top=0.97, bottom=0.2, left=0.05, right=0.97, hspace=0.2)

df.plot(ax=axes[0], table=True, legend=False)
axes[0].get_xaxis().set_visible(False)

df.plot(ax=axes[1], table=np.round(df.T, 2), legend=False)
axes[1].get_xaxis().set_visible(False)

df.plot(ax=axes[2], legend=False)

import pandas.tools.plotting as plotting
plotting.table(axes[2], np.round(df.describe(), 2),
               loc='upper right', colWidths=[0.2, 0.2, 0.2])

plt.show()

Outputs:
figure_table

@sinhrks sinhrks changed the title Plotting DataFrame/Series with matplotlib.table ENH/VIS: Plotting DataFrame/Series with matplotlib.table Mar 18, 2014
@jreback
Copy link
Contributor

jreback commented Mar 18, 2014

@TomAugspurger pls have a look at this when you get a chance

@jreback jreback added this to the 0.14.0 milestone Mar 18, 2014
@jreback
Copy link
Contributor

jreback commented Mar 18, 2014

pls add the release note to v0.14.0 as well

@jreback
Copy link
Contributor

jreback commented Apr 6, 2014

@sinhrks can you rebase this?

@jreback
Copy link
Contributor

jreback commented Apr 6, 2014

also, can you add an example in plotting.rst using this?

@@ -2590,6 +2603,51 @@ def _grouped_plot_by_column(plotf, data, columns=None, by=None,
return fig, axes


def table(ax, data, transpose=False, rowLabels=None, colLabels=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we get rid of the transpose argument? It's probably easier for people to do table(ax, data.T) rather than table(ax, data, transpose=True). Fewer arguments too. That should also go along better with the rowLabels and colLabels arguments. If we have transpose=True and rowLabels=None is it the index of the original data or the transposed data? If we get rid of transpose then they pass data.T it's clear what rowLabels refers to.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also change rowLables -> row_labels and colLabels -> col_labels for PEP8 style

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, transpose can be removed. It was for draw horizontal table by series which doesn't have transpose little easily, but it can be done once casted to DataFrame.

rowLabels and colLabels are derived from matplotlib. Thus I think it shouldn't be changed. I'll modify the comment to indicate that these are mpl keywords.

@TomAugspurger
Copy link
Contributor

When you put the example in plotting.rst, maybe note that you can get the table from the axes object with ax.tables. That way they can easily tweak the formatting.

I don't think that we should do much try to automatically format the tables well. I'm guessing this is something that doesn't have a great general solution.

@TomAugspurger
Copy link
Contributor

Let me know when you get those changes and rebased and I'll merge. Thanks and sorry for missing this when you submitted the PR.

@sinhrks
Copy link
Member Author

sinhrks commented Apr 7, 2014

@TomAugspurger Thanks for your review and comments.

I've added examples to plotting.rst and modified based on your comments except keyword name. As answered in above, these are defined in MPL so I think it is better to use as it is, clarifying these are from MPL.

TomAugspurger pushed a commit that referenced this pull request Apr 7, 2014
ENH/VIS: Plotting DataFrame/Series with matplotlib.table
@TomAugspurger TomAugspurger merged commit 4663353 into pandas-dev:master Apr 7, 2014
@TomAugspurger
Copy link
Contributor

Agreed about sticking with the MPL keywords. Good call. Thanks @sinhrks!

@jreback
Copy link
Contributor

jreback commented Apr 7, 2014

hmm....the first example in the docs is not printing the table
is this a version issue? 2.7 builds with matplotlib 1.1.1 (is this too old)?

http://pandas-docs.github.io/pandas-docs-travis/visualization.html#plotting-with-table

@TomAugspurger
Copy link
Contributor

It actually may be a figsize thing. It looks like it is plotting the table but it gets cut off.

@TomAugspurger
Copy link
Contributor

I'm looking into this btw.

@jreback
Copy link
Contributor

jreback commented Apr 7, 2014

@TomAugspurger when you update can you add a link in v0.14.0 to the docs for table plotting? thanks

@TomAugspurger
Copy link
Contributor

I'm not able to reproduce this locally, so I haven't found out what's causing the problem. The good news is that it's not mol 1.1.1 related. I was unable to reproduce it with that also.

These are built by travis right? So there's no way to get access to the machine as its building?

@jreback
Copy link
Contributor

jreback commented Apr 7, 2014

I think you could in your branch push something up with the flag to turn doc builds on and the n have it dump whatever output you need (e.g. just use print statements)

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.

matplotlib table
3 participants