-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: plotting function for "2D histograms"/"dynamic spectra" (similar to heatmap) #33560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@Rik-de-Kort This solution looks awesome! However, when I try to run your code, there is nothing shown on my screen. Do you know how to solve that? Thanks |
Ah yes, add |
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem?
I often need to plot a heatmap of a DataFrame which uses an
IntervalIndex
as its columns (and, usually, time as its index). Such a plot could also be called a "dynamic spectrum" or "2D histogram" and is used to quickly get an idea of how a spectrum develops over time.This is slightly different from what is usually considered as a heatmap (see #19008 for an example) as the bins are not necessarily equidistant and there is not necessarily a separate label for each bin. The y axis (which is used for the
IntervalIndex
) could even have logarithmic scaling.Describe the solution you'd like
This could use the same API
df.plot(type='heatmap')
as suggested in #19008 and switch between appropriate axis scaling/labeling modes depending on whether aCategoricalIndex
,IntervalIndex
or other types of indices are used.Describe alternatives you've considered
My current implementation (see below) uses matplotlib's
pcolormesh
, but needs to do some fiddling with the bin edges to work correctly.Matplotlib's
hist2d
does not work for this use case, because the data is already stored in histogrammed form - the histogram and its bins don't need to be calculated, just plotted.Seaborn's
heatmap
function seems to be limited to plotting categorical data, so bothIntervalIndex
andDatetimeIndex
are displayed as categorical data with one label per bin, equidistant spacing, and values on the y axis sorted from top to bottom instead of bottom to top:Additional context
My current implementation looks similar to this:
This only works if the
IntervalIndex
has no gaps and is non-overlapping, which would have to be checked first.The text was updated successfully, but these errors were encountered: