Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Colorbars not working when using make_axis_locatable #337

Open
theRealSuperMario opened this issue Oct 6, 2019 · 0 comments
Open

Colorbars not working when using make_axis_locatable #337

theRealSuperMario opened this issue Oct 6, 2019 · 0 comments

Comments

@theRealSuperMario
Copy link
Contributor

theRealSuperMario commented Oct 6, 2019

After checking the related issues to colorbars (#111 , #115 ), I found that the colorbar is not working when using this snippet https://stackoverflow.com/questions/32462881/add-colorbar-to-existing-axis

Is there a quick fix for it?

from matplotlib import pyplot as plt
import matplotlib2tikz
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable

RC_PARAMS = {"figure.figsize": [5, 5], "figure.dpi": 220, "pgf.rcfonts": False}

data = np.zeros((3, 3))
data[:2, :2] = 1.0

with plt.rc_context(rc=RC_PARAMS):
    fig, ax = plt.subplots(1, 1, figsize=(5, 5))
    im = ax.imshow(data)
    ax.set_title("Works")
    ax.set_axis_off()
    plt.colorbar(im, ax=ax, orientation="horizontal")
    matplotlib2tikz.save("test1.tikz")

plt.close()

with plt.rc_context(rc=RC_PARAMS):
    fig, ax = plt.subplots(1, 1, figsize=(5, 5))
    im = ax.imshow(data)
    ax.set_title("Doesn't")
    ax.set_axis_off()
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    plt.colorbar(im, cax=cax)
    matplotlib2tikz.save("test2.tikz")

Screenshot_20191006_075740

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

No branches or pull requests

1 participant