Skip to content

Allow user to insert existing figure into specific grid #53

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

Open
smeng10 opened this issue Feb 26, 2019 · 3 comments
Open

Allow user to insert existing figure into specific grid #53

smeng10 opened this issue Feb 26, 2019 · 3 comments
Labels
question Further information is requested

Comments

@smeng10
Copy link
Collaborator

smeng10 commented Feb 26, 2019

Can we add an insert function to let users insert their premade figures into specific grids?

@smeng10 smeng10 added the question Further information is requested label Feb 26, 2019
@pganssle
Copy link
Member

Can you clarify what you mean by this? If I understand correctly, that seems out of scope for this project, which is really more intended to handle the subplot geometry, and you can do with that as you wish using the normal matplotlib API.

What kind of use case were you thinking of, though? Even if it's out of scope for this project, it might be worth including in the documentation.

@smeng10
Copy link
Collaborator Author

smeng10 commented Feb 26, 2019

What I was thinking was when we trying to make the presentation, we had a lot of pain on how to insert pre-generated figures (sin functions to the power of number of grids) into the specs. We can only plot the figures on the go.
i.e

t1 = np.arange(-5.0, 5.0, 0.2)
specs1 = strategies.SquareStrategy("left").get_grid(5)
for i, sub in enumerate(specs1):
    plt.subplot(sub)
    plt.plot(t1, np.sin(t1) ** i)
plt.show()

In my view, it is hard for me to find a way inserting a figure into specific grid, what I want to do is:

#pre-generated figures sin_0 through sin_4 are the same as 
#plt.plot(t1, np.sin(t1) ** i) in the previous code
images = [sin_0, sin_1, sin_2, sin_3, sin_4]
specs1 = strategies.SquareStrategy("left").get_grid(5)
for i, sub in enumerate(specs1):
    # This is wrong but what I was tring to do is
    # if I can have another feature to just insert any image I want in any order
    # this might be helpful because I can have images = [sin_3, sin_0, sin_2, sin_1, sin_4]
    # and still insert into the grids using my order. 
    # But it is harder to do in the previous example

    # i means which grid is the target grid, and
    # image[i] means which image to insert into the target grid.
    sub.insert(i,images[i])
plt.show()

Or maybe I can figure out a matplotlib way and do a documentation example.

@tacaswell
Copy link
Member

The way Matplotlib is designed we don't really have the concept of embedding a Figure an another Figure. I suggest having a look at https://matplotlib.org/tutorials/introductory/usage.html#coding-styles for how we suggest to write helper functions for this usage. Something like:

t1 = np.arange(-5.0, 5.0, 0.2)
def helper(ax, i):
    return ax.plot(t1, np.sin(t1)**i)

specs1 = strategies.SquareStrategy("left").get_grid(5)
fig = plt.figure()
for i, sub in enumerate(specs1):
    ax = fig.add_subplot(sub)
    helper(ax, i)

which for this case is a bit of overkill, but starts to be worth it as helper gets longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants