e-hulten / july

A small library for creating pretty heatmaps of daily data.
MIT License
209 stars 26 forks source link

Add colorbar argument to july.calendar_plot() #22

Open bkimball98 opened 2 years ago

bkimball98 commented 2 years ago

Hey there,

Just throwing this idea out; I think having a legend next to the individual months [shown below] would be a nice feature to have as an arg to july.calendar_plot(). If I'm blind and it already exists, could you let me know where?

Thanks, BK Calendar

RAraghavarora commented 2 years ago

You can generate a new colorbar, by creating your own mappable:

july.calendar_plot(df2['DATE'], df['MOOD'], cmap=cMap)

# Create Mappable for colorbar
norm = Normalize(vmin=0, vmax=2)
sm = plt.cm.ScalarMappable(cmap=cMap, norm=norm)
sm.set_array([])
N = 3

# Generate colorbar
cbar = plt.colorbar(sm, ticks=np.linspace(0, 2, N), boundaries=np.arange(-0.05, 2.1, .1))
csteele2 commented 1 year ago

Doesn't that previous response generate a colormap that may or may not have the same bounds as the calendar? It seems that this code does not allow the passing of vmin, vmax, or a norm, so how it applies the colormap might not be what is intended.