1

How can I use xlim / ylim with a hist2d plot ?

With the following code, the limits are applied but inline, the properly sized plot is displayed in a larger figure.

Without xlim / ylim, the plot is properly displayed.

%matplotlib inline

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib.colors import LogNorm

data = pd.DataFrame(np.random.randint(0,101,(10000,2)), columns=['A','B'])

fig = plt.figure()
ax = fig.add_subplot(111)
(counts, ex, ey, img) = ax.hist2d(data['A'], data['B'], bins=(100,100), cmap="jet", norm=LogNorm(), alpha=.8)
ax.set_xlim(0,20)
ax.set_ylim(0,20)
geof2832
  • 136
  • 3
  • That is indeed very strange. The issue is reproducible in jupyter but running as a script works as expected. As a workaround you could run it in `%matplotlib notebook` mode but I agree that this is an annoying issue. – ImportanceOfBeingErnest Feb 01 '17 at 23:00
  • 1
    Adding this line seems to help but I don't know about the side-effects : `%config InlineBackend.print_figure_kwargs={'bbox_inches':None}` – geof2832 Feb 02 '17 at 19:56

0 Answers0