ppinard / matplotlib-colorbar

Provides a new artist for matplotlib to display a colorbar
BSD 2-Clause "Simplified" License
7 stars 3 forks source link

Colorbar size depends on data scale #12

Open nrhinehart opened 5 years ago

nrhinehart commented 5 years ago

The scale of the drawn colorbar is not independent of the data scale.

The following code generates the following image

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
from matplotlib_colorbar.colorbar import Colorbar
%matplotlib inline
data = np.array(plt.imread(cbook.get_sample_data('grace_hopper.png')))
mappable = plt.imshow(data[...,0],  cmap='viridis')
colorbar = Colorbar(mappable, location='lower left')
plt.gca().add_artist(colorbar)

image

Modifying the data scale (by multiplying by 15) with the following code generates this image

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
from matplotlib_colorbar.colorbar import Colorbar
%matplotlib inline
data = np.array(plt.imread(cbook.get_sample_data('grace_hopper.png')))
mappable = plt.imshow(data[...,0]*15,  cmap='viridis')
colorbar = Colorbar(mappable, location='lower left')
plt.gca().add_artist(colorbar)

image

ppinard commented 4 years ago

This should now be fixed in version 0.4.0.