Skip to content

Commit

Permalink
fix bug in linear bars plotting shifting norm levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhsmit committed Nov 29, 2023
1 parent efe7f5b commit e86bf4d
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions pyhdx/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ def linear_bars_figure(
if norm is None:
raise ValueError("No valid Norm found")


reduced = data.xs(level=-1, key=field, axis=1)

if groupby:
Expand All @@ -619,7 +618,7 @@ def linear_bars_figure(

flat = reduced.columns.to_flat_index().tolist()
series_list = [reduced[col] for col in reduced.columns]

# nest the individual pandas series in a dict according to grp / bar level
result = defaultdict(dict)
for tup, series in zip(flat, series_list):
Expand All @@ -645,7 +644,6 @@ def linear_bars_figure(
return fig, axes, cbar



def linear_bars(
data: dict[str, dict[str, pd.Series]],
norm,
Expand All @@ -669,7 +667,6 @@ def linear_bars(
cbar: The colorbar object.
"""


hspace = [elem for v in data.values() for elem in [0] * (len(v) - 1) + [None]][:-1]
ncols = 1
nrows = len(hspace) + 1
Expand All @@ -688,20 +685,28 @@ def linear_bars(
ax = next(axes_iter)
rmin, rmax = values.index.min(), values.index.max()
r_edges = pplt.arange(rmin - 0.5, rmax + 0.5, 1)
ax.pcolormesh(r_edges, y_edges, values.to_numpy().reshape(1, -1), cmap=cmap, norm=norm)
ax.pcolormesh(
r_edges,
y_edges,
values.to_numpy().reshape(1, -1),
cmap=cmap,
vmin=norm.vmin,
vmax=norm.vmax,
levels=256,
)
ax.format(yticks=[])

ax.text(
1.02,
0.5,
label,
horizontalalignment="left",
verticalalignment="center",
transform=ax.transAxes,
)
1.02,
0.5,
label,
horizontalalignment="left",
verticalalignment="center",
transform=ax.transAxes,
)

if i == 0:
ax.format(title=top_level)
ax.format(title=top_level)

axes.format(xlabel=r_xlabel)

Expand Down Expand Up @@ -953,7 +958,9 @@ def redundancy(ax, hdxm, cmap=None, norm=None):
img,
extend="max",
cmap=cmap,
norm=norm,
vmin=norm.vmin,
vmax=norm.vmax,
levels=256,
)
ax.format(yticks=[], title="Redundancy")
return collection
Expand All @@ -976,7 +983,9 @@ def resolution(ax, hdxm, cmap=None, norm=None):
img,
extend="max",
cmap=cmap,
norm=norm,
vmin=norm.vmin,
vmax=norm.vmax,
levels=256,
)
ax.format(yticks=[], title="Resolution")
return collection
Expand All @@ -993,7 +1002,16 @@ def single_linear_bar(ax, x, z, cmap, norm, **kwargs):

img = np.expand_dims(z, 0)

collection = ax.pcolormesh(pplt.edges(x), np.array([0, 1]), img, cmap=cmap, norm=norm, **kwargs)
collection = ax.pcolormesh(
pplt.edges(x),
np.array([0, 1]),
img,
cmap=cmap,
vmin=norm.vmin,
vmax=norm.vmax,
levels=256,
**kwargs,
)
ax.format(yticks=[])

return collection
Expand Down

0 comments on commit e86bf4d

Please sign in to comment.