8000 GSOC: Categorical Axes by story645 · Pull Request #6612 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

GSOC: Categorical Axes #6612

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

Closed
wants to merge 0 commits into from
Closed

GSOC: Categorical Axes #6612

wants to merge 0 commits into from

Conversation

story645
Copy link
Member
@story645 story645 commented Jun 20, 2016

This is an ongoing PR and mostly exists to make it easier for @mdboom and @tacaswell to follow what I'm working on and to solicit comments from the other matplotlib developers. The aim is to add support for categorical data, a first pass being adding nominal support for plotting lists of strings (and pandas dateframes) using the unitConversionInterface. I'm working out support for lists of strings phase of this project mostly because I'm not sure how to do type inspection on a dateFrame to see if it's categorical and then how to unpack the dateframe...

Currently using the following as models/getting lost in these weeds:

And would be much obliged if somebody could tell me when these convertors actually kick in. So confused about that....my working framework is that when it comes to the steps involved:
convert: converts input items into floats
axis_info: registers which locators and formatters to use
defualt_units: returns units (often none)
and so:
locator: categorical arguably fixed/show all ticks/categories
formatter: this is what actually labels the categories with the data that gets passed in

And sorry for the commit messages. Every attempt at rebasing has created yet more of 'em.

majfmt = CategoricalLocator()
seq, locs = zip(*axis.unit_data.items())
majloc = CategoricalFormatter(locs)
majfmt = CategoricalLocator(seq)
Copy link
Member

Choose a reason for hiding this comment

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

These lines are flipped.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah just saw that (was caught because of a failing test!) and fixed it, will commit up

@tacaswell
Copy link
Member

I suggest worrying less about tests at this point and more about getting and end-to-end demonstration that produces a plot with no fatal exceptions.

@story645
Copy link
Member Author
story645 commented Jun 23, 2016

The thing is the tests are helping me debug what's breaking my code. At the moment, I can generate a plot, with no exceptions, but the labeling and ticks are off (probably due to vmin/vmax issues going by some test results) so that's where I'm working at.

import matplotlib.pyplot as plt

#cat is the import reference to categorical.py
cat.register()
x = ['a','b','c','d']
y = [1, 2, 3, 4]
plt.plot(x,y)

index

@tacaswell
Copy link
Member

If the tests are helping you, then by all means keep using them. Just try not to let getting full test coverage slow down getting a working prototype.

@story645
Copy link
Member Author
story645 commented Jun 23, 2016

Thanks. So I've pinned it down a bit more, in that ticks get set and labels don't:

print(ax.get_xticks())
print(list(ax.get_xticklabels()))

yields:

[0 1 2 3]
[Text(0,0,''), Text(0,0,''), Text(0,0,''), Text(0,0,'')]

The bug is that unit_data isn't getting set as expected and that's messing with everything

@story645
Copy link
Member Author
story645 commented Jun 23, 2016

Though as an aside, despite unit_data going wonky, the ticking works even for repeating values, so the conversion apparently works:

x = ['a','b','c','a']
y = [1, 2, 3, 4]

yields:
index

and the formatter yields what it's supposed to:

form = ax.xaxis.get_major_formatter()
print([form('',i) for i in range(3)])

yields

['a', 'b', 'c']

"""Holds data that a ConversionInterface subclass relys on
to convert between labels and indexes
"""
return self._unit_data
Copy link
Member

Choose a reason for hiding this comment

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

You should create an empty unit_data in the __init__ to avoid strange exception is someone calls the getter before the setter.

@tacaswell
Copy link
Member

With this branch

 plt.bar(['a', 'b', 'c'], [1, 2, 3], align='center')

so

@story645
Copy link
Member Author
story645 commented Jun 27, 2016

UGH! Python 3 dicts are special, so now a todo is wrapping support for them as otherwise this doesn't work and it's my default use case so it has to work:

a = {'a':1, 'b':2, 'c':3}
plt.plot(a.keys(), a.values())

Which question, can we chain convertors? or should this be wrapped into a decorator..?

@story645
Copy link
Member Author
story645 commented Jul 4, 2016

This is closed 'cause I finally got around to the proper methodology of branches for each feature, but it's probably not terrible to since this one was getting really messy anyway.

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
0