Skip to content

Commit

Permalink
plotting typing / tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhsmit committed Sep 28, 2023
1 parent a0fc8a1 commit 4ad4a6f
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions pyhdx/plot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from contextlib import contextmanager
from copy import copy
from pathlib import Path
from typing import Optional, Type, Union
from typing import Optional, Type, Union, Tuple

import matplotlib as mpl
import matplotlib.pyplot as plt
Expand All @@ -14,6 +14,7 @@
from tqdm import tqdm
import colorcet as cc

from matplotlib.colorbar import Colorbar
from pyhdx.config import cfg
from pyhdx.fileIO import load_fitresult
from pyhdx.support import (
Expand Down Expand Up @@ -870,17 +871,18 @@ def rainbowclouds(
def colorbar_scatter(
ax,
data: pd.DataFrame,
y:str="dG",
yerr:str="covariance",
y: str = "dG",
yerr: str = "covariance",
cmap=None,
norm=None,
cbar:bool=True,
cbar_kwargs:Optional[dict]=None,
invert_yaxis:bool=False,
symmetric:bool=False,
sclf:float=1e-3,
cbar: bool = True,
cbar_kwargs: Optional[dict] = None,
invert_yaxis: bool = False,
symmetric: bool = False,
ylim: Optional[Tuple[float, float]] = None, # overridees invert / symmetric
sclf: float = 1e-3,
**kwargs,
):
) -> Optional[Colorbar]:
# todo make error bars optional
# todo custom ylims? scaling?
try:
Expand Down Expand Up @@ -917,15 +919,18 @@ def colorbar_scatter(

# todo this function should be more general and should take `invert_yaxis` and `symmetric` kwargs

ylim = ax.get_ylim()
if (ylim[0] < ylim[1]) and invert_yaxis and symmetric:
ylim = np.max(np.abs(ylim))
ax.set_ylim(ylim, -ylim)
elif (ylim[0] < ylim[1]) and invert_yaxis:
ax.set_ylim(*ylim[::-1])
elif y == "ddG":
ylim = np.max(np.abs(ylim))
ax.set_ylim(ylim, -ylim)
if ylim is not None:
ax.set_ylim(*ylim)
else:
ylim = ax.get_ylim()
if (ylim[0] < ylim[1]) and invert_yaxis and symmetric:
ylim = np.max(np.abs(ylim))
ax.set_ylim(ylim, -ylim)
elif (ylim[0] < ylim[1]) and invert_yaxis:
ax.set_ylim(*ylim[::-1])
elif y == "ddG":
ylim = np.max(np.abs(ylim))
ax.set_ylim(ylim, -ylim)

if cbar:
cbar_norm = copy(norm)
Expand Down

0 comments on commit 4ad4a6f

Please sign in to comment.