Skip to content
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

[feat] Could orientation="vertical" be added? #186

Open
LovelyBuggies opened this issue Sep 15, 2020 · 8 comments
Open

[feat] Could orientation="vertical" be added? #186

LovelyBuggies opened this issue Sep 15, 2020 · 8 comments

Comments

@LovelyBuggies
Copy link
Contributor

LovelyBuggies commented Sep 15, 2020

Hello,

We are designing a lib based on boost-histogram and mplhep. We want to build a plotting function that can draw the 2d histogram and its projections with respect to different axes - plot2d_full in scikit-hep/hist#80.

Everything goes well except this:

import boost_histogram as bh
import mplhep
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.transforms as transforms


h = bh.Histogram(bh.axis.Regular(50, -5, 5),
                 bh.axis.Regular(50, -5, 5))

h.fill(
    np.random.normal(size=50_000), np.random.normal(size=50_000)
)

fig = plt.figure(figsize=(5, 5))
grid = fig.add_gridspec(5, 5, hspace=0, wspace=0)

ax1 = fig.add_subplot(grid[1:5, 0:4])
ax2 = fig.add_subplot(grid[0:1, 0:4], sharex=ax1)
ax3 = fig.add_subplot(grid[1:5, 4:5], sharey=ax1)

ax1 = mplhep.hist2dplot(h, ax=ax1, cbar=False)
ax2 = mplhep.histplot(
            h.project(1),
            ax=ax2,
            lw=4
        )


base = plt.gca().transData
rot = transforms.Affine2D().rotate_deg(270)
ax3 = mplhep.histplot(
    h.project(0),
    ax=ax3,
    transform=rot + base,
    lw=4,
)

We expect an output like this:

image

But actually it comes to this:

image

And I find the rotation is not properly displayed:

mplhep.histplot(
    h.project(0),
    transform=rot + base,
    lw=4
)

image

Could you help to find if there is any problem with histplot or where I do mistakenly?

By the way, @henryiii thought using Line2d and QuadMesh, etc. would be a better idea for the return types of histplot/2d, do you think so?

Thanks!

@andrzejnovak
Copy link
Member

andrzejnovak commented Sep 15, 2020

Hi @LovelyBuggies, what you get pretty much makes sense. histplot does not have a "horizontal" option, but I think it's also a bit of an overkill to use in this case, since you basically won't use any of its other features.

I would rather think the 2d plot you already have implemented could be factored out and put into mplhep, that way it would be a free-standing function you could use on any 2d histogram. What do you think?

@LovelyBuggies
Copy link
Contributor Author

Nice if you have a function named histplot2d_full, then I can directly call it in hist and it wouldn't be "overkill" as you said.

Btw, we have another plotting function plot_pull and plotting methods that you can refer to ref., if you want to add them to mplhep.

@andrzejnovak
Copy link
Member

@LovelyBuggies Would you like to contribute that or should I just scoop it out of hist? I think this could well be an option of the histplot2d fcn rather than a standalone thing.

@LovelyBuggies
Copy link
Contributor Author

LovelyBuggies commented Sep 15, 2020

@andrzejnovak You can scope it out of hist 😀 . Feel free to update this thread, we are waiting to update a new version of hist that based on this feature. I am willing to help if you are meeting some problems.

@henryiii
Copy link
Member

I think having the ability to rotate could be useful standalone, and a histplot2d(skylines=True) could then potentially be composed of two of these, or even if it isn't, it might be useful to have it first?

@henryiii
Copy link
Member

Request: plt.hist has orientation="vertical", histplot should have it too!

@henryiii
Copy link
Member

henryiii commented Sep 26, 2020

There's a mistake in the original problem code:

-base = plt.gca().transData
+base = ax3.transData

With this correction, the code above works fine. I would still recommend an orientation="vertical" shortcut (which basically does exactly the code above), but I think otherwise, it is fine.

@henryiii henryiii changed the title Rotation Not Properly Display in histplot [feat] Could orientation="vertical" be added? Sep 26, 2020
@andrzejnovak
Copy link
Member

I'm going to wait for matplotlib 3.4 to come out with plt.stairs which will make the vertical implementation cleaner.

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

No branches or pull requests

3 participants