fix heatmap when spacing in not equal

Histogram2d was binning data, even if axes values were not
on a linear scale, creating some strange figures. We
do not need the binning here.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-07-12 21:15:08 +02:00
parent 562ef5122f
commit 0dfbace655
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
1 changed files with 3 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import time
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
import pandas as pd
import seaborn as sns import seaborn as sns
from itertools import combinations from itertools import combinations
from mplfinance.original_flavor import candlestick_ohlc from mplfinance.original_flavor import candlestick_ohlc
@ -197,10 +198,9 @@ class Visualizer:
ylabels = np.sort(np.unique(data[key][labels[1]])) ylabels = np.sort(np.unique(data[key][labels[1]]))
if len(xlabels) < self.minimumDataPoints or len(ylabels) < self.minimumDataPoints: if len(xlabels) < self.minimumDataPoints or len(ylabels) < self.minimumDataPoints:
continue continue
hist, xedges, yedges = np.histogram2d(data[key][labels[0]], data[key][labels[1]], bins=(len(xlabels), len(ylabels)), weights=data[key]['ttas']) df = pd.DataFrame.from_dict(data[key]).pivot(labels[0], labels[1], 'ttas')
hist = hist.T
fig, ax = plt.subplots(figsize=(10, 6)) fig, ax = plt.subplots(figsize=(10, 6))
sns.heatmap(hist, xticklabels=xlabels, yticklabels=ylabels, cmap='hot_r', cbar_kws={'label': 'Time to block availability (ms)'}, linecolor='black', linewidths=0.3, annot=True, fmt=".2f", ax=ax, vmin=vmin, vmax=vmax) sns.heatmap(df, cmap='hot_r', cbar_kws={'label': 'Time to block availability (ms)'}, linecolor='black', linewidths=0.3, annot=True, fmt=".2f", ax=ax) #vmin=vmin, vmax=vmax
plt.xlabel(self.formatLabel(labels[0])) plt.xlabel(self.formatLabel(labels[0]))
plt.ylabel(self.formatLabel(labels[1])) plt.ylabel(self.formatLabel(labels[1]))
filename = "" filename = ""