Skip to content

Relative positioning for annotations #939

Open
@has2k1

Description

@has2k1

I had the same problem, because I wanted to place some annotation at exactly 90% of the y axis.

I solved it like this:

(basically the same as has2k1s solution)


p = (p9.ggplot(...))

fig = p.draw()

ax = fig.axes[0]



y_min, y_max = ax.get_ylim()

x_min, x_max = ax.get_xlim()

if you know the limits you can do something like this

my x axes is a date so


import matplotlib.dates as mdates

annotation_x1 = mdates.num2date(x_min + .05 *(x_max-x_min))

annotation_y = 0.9 *y_max





p_final = p + p9.annotate('text', 

                x= annotation_x1,

                y= annotation_y, 

                label='whatever,

                ha = 'left',

                size=16,

            )

of course a pure plotnine solution would be highly welcome!

Originally posted by @TerryGamon in #906

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions