Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ConnectionPatch "axis fraction" failure when axesB contains a plot #2377

Closed
@JamesPHoughton

Description

@JamesPHoughton

I'm having a bit of an obscure issue drawing lines from one subplot (using data coordinates) to another subplot (using axes fraction coordinates). When the destination subplot is empty, the code works fine:

from matplotlib.patches import ConnectionPatch
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(8,8))

x=np.arange(0,10)
y=x**2

ax_1 = plt.subplot2grid([2,2], loc=[0,0])
plt.plot(x, y)

ax_2 = plt.subplot2grid([2,2], loc=[1,1])
#plt.plot(x, y)

ax_1.add_artist(ConnectionPatch(xyA=[5,25], xyB=[.5,1], 
                                coordsA="data", coordsB="axes fraction", 
                                axesA=ax_1, axesB=ax_2,
                                arrowstyle="-|>"))

image

but when the destination subplot contains a plot, the line is interpreted in data coordinates instead of the requested axes fraction coordinates:

from matplotlib.patches import ConnectionPatch
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(8,8))

x=np.arange(0,10)
y=x**2

ax_1 = plt.subplot2grid([2,2], loc=[0,0])
plt.plot(x, y)

ax_2 = plt.subplot2grid([2,2], loc=[1,1])
plt.plot(x, y)

ax_1.add_artist(ConnectionPatch(xyA=[5,25], xyB=[.5,1], 
                                coordsA="data", coordsB="axes fraction", 
                                axesA=ax_1, axesB=ax_2,
                                arrowstyle="-|>"))

image

Am I being silly? Is there a better way to do this? Or is it a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions