Skip to content

[WIP] Implement a scattertext plot method. #4063

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

Conversation

dopplershift
Copy link
Contributor

Adds a TextCollection object that facilitates drawing a bunch of text
with common properties at different locations. scattertext() uses this
to plot text in data coordinates, with an optional offset.

This is a first cut in order to get design feedback. TextCollection inherits only from Text right now, just overriding the draw() method to do multiple calls to draw_text(). The implementation here started with Text.draw(), so there are some things like bbox and PathEffects that are inherited that may or may not make sense.

Questions:

  1. How to refactor Text so that the hack for get_layout() isn't necessary
  2. Any reason to also inherit Collection
  3. Adding colormapping: using cm.ScalarMappable?
  4. Interface for scattertext(): Should it take an array of data values or an array of strings?

Any other issues?

Adds a TextCollection object that facilitates drawing a bunch of text
with common properties at different locations. scattertext() uses this
to plot text in data coordinates, with an optional offset.
@tacaswell tacaswell added this to the v1.5.x milestone Feb 2, 2015
@tacaswell
Copy link
Member

👍 For feature.

There might also be issues with the _bbox_patch and it's associated helper functions.

@dopplershift
Copy link
Contributor Author

This should address additional comments raised in #345. I'm not sure if this TextCollection has any significant performance benefits (since that's not my driving interest), but #347 may be relevant.

I'll fix the pep8 failures and add some tests once the design is vetted.

@tacaswell
Copy link
Member

I am also 👍 on not being worried about performance with this.

The ability to easily do broadcasting of interesting properties over artists is one of the places that bokeh is well ahead of us. I wonder if in addition to the Collection subclasses (which really are about performance optimizations as all of the broadcast logic lives in their draw methods) it would be worth providing a top-level generic broadcasting function, something like:

def broadcast_magic(ax, Art_cls, **kwargs):
    static_kwargs = dict()
    broadcast_names = []
    max_count = -1
    cycle_values = []
    for k, v in kwargs.items:
        if is_iterable(v) and not is_string(v):
           broadcast_name.append(k)
           cycle_values = cycle(v)
           if len(v) > max_count:
               max_count = len(v)
        else:
            static_kwargs[k] = v
    ret = []
    for count, b_vals in enumerate(zip(cycle_values)):
        if not count <max_count:
            break
        local_kwargs = dict(static_kwargs)
        local_kwargs.update({k: v for k, v in zip(broadcast_names, b_vals)})
        art = Art_cls(**local_kwargs)
        ax.add_artist(art)
        ret.append(art)
    return ret

@tacaswell tacaswell modified the milestones: proposed next point release, next point release Feb 19, 2015
@dopplershift dopplershift mentioned this pull request Apr 27, 2015
2 tasks
@tacaswell tacaswell modified the milestones: next point release, proposed next point release Jun 16, 2015
@tacaswell tacaswell modified the milestones: next point release, proposed next point release Jun 29, 2015
@OceanWolf
Copy link
Member

If you only need TextCollection to group properties, then can't we do that with ASS? As far as I see that should do the same thing but in a much more general way.

@dopplershift
Copy link
Contributor Author

@OceanWolf I'm lost on your acronym, and strangely, googling it isn't helping. :)

@WeatherGod
Copy link
Member

Artist Style Sheets. It is one of the MEPs.

On Mon, Jun 29, 2015 at 2:32 PM, Ryan May notifications@github.com wrote:

@OceanWolf https://github.com/OceanWolf I'm lost on your acronym, and
strangely, googling it isn't helping. :)


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

@dopplershift
Copy link
Contributor Author

It's unclear to me if MEP26 is relevant. I want to easily be able to put a bunch of text on a plot, all with the same style (maybe changing color, but that's all). This facilitates plotting many text values (or even just strings) in data coordinates, often offset from the center location.

This can certainly be accomplished now directly with a for loop; this seems inefficient and verbose. TextCollection would essentially let Text take arrays. As far as I can tell, ASS would simply be a better way to do the for loop method.

@tacaswell tacaswell modified the milestones: next point release, proposed next point release Jul 16, 2015
@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Aug 29, 2017
@tacaswell
Copy link
Member

This should inherit from Collection so that it may be color-mappable and such.

@jklymak
Copy link
Member

jklymak commented Oct 5, 2018

No objections to this being re-opened, but closing because its been 3 years, and I'm not entirely sure what the advantage is over just having a for-loop to add the text (and creating a list of handles if you want to store them for future reference). I imagine most folks who want this are getting by using this method.

@jklymak jklymak closed this Oct 5, 2018
@anntzer
Copy link
Contributor

anntzer commented Oct 6, 2018

It's relevant to #5665 (moving ticks to use LineCollections instead of individual lines would (perhaps) logically move label texts to TextCollections as well). But I'm fine leaving this closed for now, we can always revisit it later.

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.

7 participants