Skip to content
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

horizontal scaling of 10+ axes with figrid #2

Open
oliche opened this issue Dec 10, 2024 · 0 comments
Open

horizontal scaling of 10+ axes with figrid #2

oliche opened this issue Dec 10, 2024 · 0 comments

Comments

@oliche
Copy link
Member

oliche commented Dec 10, 2024

Hello,

For multiple probe displays I get an issue trying to use figrid specifically, if I use many axes, some of them do not keep the same scale. It changes according to the number of axes, for example here with N=11 and 13.

At first I thought it was because of the labels, so I did plot the same insertion over and over again. Still the same.
The get_coords is also fine, the diffs are constant so I think the issue may lie with figrid.

Have you ever encountered this and found a fix ?

# %%
from pathlib import Path

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

from ibl_style.style import figure_style
from ibl_style.utils import MM_TO_INCH, get_coords
import figrid as fg


import ephys_atlas.data
import brainbox.ephys_plots
import iblatlas.atlas
import iblatlas.plots

ba = iblatlas.atlas.AllenAtlas()
regions = iblatlas.atlas.BrainRegions()
figure_style()
FIG_SIZE = (13, 6)


pids = ephys_atlas.data.BENCHMARK_PIDS
n_pids = len(pids)
path_features = Path('/Users/olivier/Documents/datadisk/Data/paper-ephys-atlas/ephys-atlas-decoding/features/2024_W50')  # mac
path_features = Path('/mnt/s0/ephys-atlas-decoding/features/2024_W50')  # parede
df_voltage = pd.read_parquet(path_features / 'raw_ephys_features_denoised.pqt')

ax_ratios =  np.r_[np.ones(n_pids), 2, 8]

# Make a double column figure
fig = plt.figure(figsize=FIG_SIZE)

# Get the dimensions of the figure in mm
width, height = fig.get_size_inches() / MM_TO_INCH
xspans = get_coords(width, ratios=ax_ratios, space=15, pad=5, span=(0, 1))
yspans = get_coords(height, ratios=[1], space=[20], pad=5, span=(0, 1))
ax = [fg.place_axes_on_grid(fig, xspan=xspans[i], yspan=yspans[0]) for i in range(len(ax_ratios))]

ba.plot_top(ax=ax[-1])

for i, pid in enumerate(pids):
    df_pid = df_voltage.loc[pids[0]]
    depth = df_pid.groupby('axial_um').agg(atlas_id=pd.NamedAgg(column='atlas_id', aggfunc='first')).reset_index()
    brainbox.ephys_plots.plot_brain_regions(
        depth['atlas_id'].values, channel_depths=depth['axial_um'].values,
        brain_regions=regions, display=True, ax=ax[i])
    ax[-1].plot(df_pid['x'].values * 1e6, df_pid['y'].values * 1e6, '.', color='r', markersize=2)
    ax[-1].plot(df_pid['x'].values[-1] * 1e6, df_pid['y'].values[-1] * 1e6, '*', color='k', markersize=2)


for i in range(13, 15):
    ax[i].axis('off')

def adjust_figure(fig):
    # Remove 7.5 mm of whitespace around figure in all directions
    adjust = 7.5
    # Depending on the location of axis labels leave a bit more space
    extra =  5
    width, height = fig.get_size_inches() / MM_TO_INCH
    fig.subplots_adjust(top=1-adjust/height, bottom=(adjust + extra)/height,
                        left=(adjust + extra)/width, right=1-adjust/width)
adjust_figure(fig)

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant