davidfokkema / artist

Artist makes beautiful plots
http://davidfokkema.github.io/artist/
GNU General Public License v3.0
12 stars 2 forks source link

Colorbar for 2D Histograms #37

Closed 153957 closed 8 years ago

153957 commented 8 years ago

It would be nice to have colorbar support for 2D histograms.. There is a colorbar support for the scatter_table method, but not yet for histogram2d.

153957 commented 8 years ago

See page 261 of the PGFPlots manual:

you can also set point meta min and point meta max manually in order to draw a colorbar.

These values can be set using the mlimits in artist, which are used to limit the color range for scatter_table plots. This can be used to 'manually' make a colorbar for histogram2d in artist using:

plot = Plot()
x = random.normal(0, 10, 10000)
y = random.uniform(0, 1, 10000)
counts, xbins, ybins = np.histogram2d(x, y, 25)
plot.histogram2d(counts, xbins, ybins)
plot.set_mlimits(counts.min(), counts.max())
plot.set_colorbar()
plot.set_colormap('blackwhite')
plots.save_as_pdf('histogram2d_colorbar')

histogram2d_colorbar

davidfokkema commented 8 years ago

Agreed, would be very nice!

153957 commented 8 years ago

It works, but not for multiplots, or multiple histogram2d plots in a single plot. This is because the mlimits (min/max counts in a bin) might differ between plots, this is not accounted for when making multiple plots. For each histogram2d the min/max colors are scaled between the min/max values for that plot.

screen shot 2016-05-04 at 16 36 13

davidfokkema commented 8 years ago

Great! Sometimes I think we should drop pgfplots and just use TikZ. More work, but more control.

153957 commented 8 years ago

The main problem with that is the 'more work' part.. (#4)

153957 commented 8 years ago

Mostly implemented in ea83fb9aba878bc9c9e1a424eb967cab29bf9c6d

davidfokkema commented 8 years ago

Nice, thanks!