bendichter / brokenaxes

Create matplotlib plots with broken axes
MIT License
518 stars 45 forks source link

text and annotate ignores brokenaxes limits #68

Closed EKukstas closed 3 years ago

EKukstas commented 3 years ago

I want to annotate my plots with strings but both 'text' and 'annotate' ignore the axis limits set by brokenaxes. Using one of the examples:

fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(xlims=((0, .1), (.4, .7)), hspace=.05)
x = np.linspace(0, 1, 100)
bax.plot(x, np.sin(10 * x), label='sin')
bax.plot(x, np.cos(10 * x), label='cos')
bax.legend(loc=3)
bax.set_xlabel('time')
bax.set_ylabel('value')
bax.text(0.5, 0.8, '0', rotation=90, color='C3', fontsize=12)

I get the following: brokenaxes_annotate_issue

I feel like it's a simple enough fix but can't figure out what I need to change in order to suppress the second annotation being plotted. Can anyone point me in the right direction?

bendichter commented 3 years ago

just a minor adjustment on the last line:

import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
import numpy as np

fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(xlims=((0, .1), (.4, .7)), hspace=.05)
x = np.linspace(0, 1, 100)
bax.plot(x, np.sin(10 * x), label='sin')
bax.plot(x, np.cos(10 * x), label='cos')
bax.legend(loc=3)
bax.set_xlabel('time')
bax.set_ylabel('value')
bax.big_ax.text(0.5, 0.8, '0', rotation=90, color='C3', fontsize=12)
bendichter commented 3 years ago

well... that sort of works. I think it's using [0,1], [0,1] as the coordinate space. I'll see if I can fix that

Thomas-Moore-Creative commented 4 months ago

First - thank you for coding and sharing brokenaxes !!!

well... that sort of works. I think it's using [0,1], [0,1] as the coordinate space. I'll see if I can fix that

I'm placing text labels and would like to use the actual coordinate values ( as I used to ). At the moment it is an iterative guessing approach across [0,1] range which makes it harder to generalise ( for me ). Any progress on your comment above?

bendichter commented 4 months ago

Hi @Thomas-Moore-Creative No problem, it's fun to see all the cool uses!

This appears to be working as you want for me:

import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
import numpy as np

fig = plt.figure(figsize=(5, 2))
bax = brokenaxes(xlims=((0, .01), (.04, .07)), hspace=.05)
x = np.linspace(0, .1, 100)
bax.plot(x, np.sin(100 * x), label='sin')
bax.plot(x, np.cos(100 * x), label='cos')
bax.legend(loc=3)
bax.set_xlabel('time')
bax.set_ylabel('value')

bax.text(0.045, 0.5, '0', fontsize=12)

image

this would not work if the underlying axes were [0,1],[0,1].

bendichter commented 4 months ago

Note that I am using bax.text, not bax.big_ax.text as I did in the example above