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

BUG: qbstyles adds automatic axis ticks that are not consistent with the data displayed when one subplot is used #13

Open
mathilde-lavacquery opened this issue Jan 26, 2022 · 5 comments

Comments

@mathilde-lavacquery
Copy link

mathilde-lavacquery commented Jan 26, 2022

Same image with qbstyles activated and deactivated: x-axis and y-axis are not indexed properly in the first image

# LINE PLOT
def line_plot(ax):
    rng = np.random.RandomState(4)
    x = np.linspace(0, 10, 500)
    y = np.cumsum(rng.randn(500, 4), 0)
    ax.set_title('Line Graph')
    ax.set_xlabel('— Time')
    ax.set_ylabel('— Random values')
    ax.legend(['Bitcoin', 'Ethereum', 'Dollar', 'Oil'])
    ax.set_xlim([0, 10])
    ax.set_ylim([-20, 60])
    ax.plot(x, y)

fig, ax = plt.subplots(figsize=(16, 9))
line_plot(ax)

image
image

@mathilde-lavacquery mathilde-lavacquery changed the title BUG: qbstyles adds automatic axis ticks that are not consistent with the data displayed BUG: qbstyles adds automatic axis ticks that are not consistent with the data displayed when one subplot is used Jan 26, 2022
@Quentin-M
Copy link

Same issue, it's pretty bizarre.
image

@oakif
Copy link

oakif commented Jul 10, 2022

Having this same issue as well, sadly!

@oakif
Copy link

oakif commented Jul 14, 2022

Hacky workaround by typing print(plt.rcParams) to get all rcparams, then copy and paste all those rc parameters separately. Don't use mpl_style(). You might need to restart your kernel for the changes to appear.

@simfinite
Copy link

Same problem here. It seems to be related to the minor-ticks. The mpl_style docstring says something about having to monkey-patch mpl. If minor ticks are not essential, one can call mpl_style(minor_ticks=False) to disable them (along with the monkey-patching).

@louisdecharson
Copy link

I had the same issue and it seems that it can be fixed by removing the monkey patch on figure and keeping it on subplots.

Version used

  • Python 3.10.8
  • Matplotlib 3.6.2

Examples

import marplotlib.pyplot as plt 
mpl_style(minor_ticks=False)
original_subplots = plt.subplots


def _style_ticks(axis, color):
    """Enable minor ticks, and color major + minor ticks"""
    axis.minorticks_on()
    ticks = (
        axis.get_xticklines()
        + axis.xaxis.get_minorticklines()
        + axis.get_yticklines()
        + axis.yaxis.get_minorticklines()
    )
    for tick in ticks:
        tick.set_color("#" + color + "3D")


def _monkey_patch_subplot(color, subplot):
    """Style all axes of a figure containing subplots, just after the
    figure is created."""

    def _patch(*args, **kwargs):
        fig, axes = subplot(*args, **kwargs)
        axes_list = [axes] if isinstance(axes, matplotlib.axes.Axes) else axes
        for ax in axes_list:
            if isinstance(ax, matplotlib.axes.Axes):
                _style_ticks(ax, color)
            else:
                for each in ax:
                    _style_ticks(each, color)
        return fig, axes

    return _patch


plt.subplots = _monkey_patch_subplot("FFFFFF", original_subplots)

Note for the maintainer(s), the color argument does not seem to have any effect.

image

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

5 participants