Skip to content

Commit

Permalink
example gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
markur4 committed Dec 1, 2023
1 parent 1ff4ad5 commit a094902
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 90 deletions.
53 changes: 19 additions & 34 deletions HOW_TO_USE/plot_styles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -216,49 +216,34 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## `plst.set_style()` takes any style!"
"## `plst.set_style()` takes styles from matplotlib, seaborn and plotastic!"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"plotastic:\n",
"\t['default', 'paper']\n",
"seaborn:\n",
"\t['white', 'dark', 'whitegrid', 'darkgrid', 'ticks']\n",
"matplotlib:\n",
"\t['Solarize_Light2', '_classic_test_patch', '_mpl-gallery', '_mpl-gallery-nogrid', 'bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-v0_8', 'seaborn-v0_8-bright', 'seaborn-v0_8-colorblind', 'seaborn-v0_8-dark', 'seaborn-v0_8-dark-palette', 'seaborn-v0_8-darkgrid', 'seaborn-v0_8-deep', 'seaborn-v0_8-muted', 'seaborn-v0_8-notebook', 'seaborn-v0_8-paper', 'seaborn-v0_8-pastel', 'seaborn-v0_8-poster', 'seaborn-v0_8-talk', 'seaborn-v0_8-ticks', 'seaborn-v0_8-white', 'seaborn-v0_8-whitegrid', 'tableau-colorblind10']\n"
]
},
{
"ename": "ValueError",
"evalue": "#! Style 'df' not found. Choose one from these: None",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/_REPOS/plotastic/src/plotastic/plotting/rc.py:51\u001b[0m, in \u001b[0;36mset_style\u001b[0;34m(style)\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m---> 51\u001b[0m sns\u001b[39m.\u001b[39;49mset_style(style)\n\u001b[1;32m 52\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mValueError\u001b[39;00m:\n\u001b[1;32m 53\u001b[0m \u001b[39m# styles_all_s = '\\n'.join([str(s) for s in styles_all])\u001b[39;00m\n\u001b[1;32m 54\u001b[0m \u001b[39m# ### Make a pretty printed string of styles_all dictionary\u001b[39;00m\n",
"File \u001b[0;32m~/_REPOS/plotastic/venv/lib/python3.11/site-packages/seaborn/rcmod.py:331\u001b[0m, in \u001b[0;36mset_style\u001b[0;34m(style, rc)\u001b[0m\n\u001b[1;32m 304\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 305\u001b[0m \u001b[39mSet the parameters that control the general style of the plots.\u001b[39;00m\n\u001b[1;32m 306\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 329\u001b[0m \n\u001b[1;32m 330\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m--> 331\u001b[0m style_object \u001b[39m=\u001b[39m axes_style(style, rc)\n\u001b[1;32m 332\u001b[0m mpl\u001b[39m.\u001b[39mrcParams\u001b[39m.\u001b[39mupdate(style_object)\n",
"File \u001b[0;32m~/_REPOS/plotastic/venv/lib/python3.11/site-packages/seaborn/rcmod.py:185\u001b[0m, in \u001b[0;36maxes_style\u001b[0;34m(style, rc)\u001b[0m\n\u001b[1;32m 184\u001b[0m \u001b[39mif\u001b[39;00m style \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m styles:\n\u001b[0;32m--> 185\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mstyle must be one of \u001b[39m\u001b[39m{\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m, \u001b[39m\u001b[39m'\u001b[39m\u001b[39m.\u001b[39mjoin(styles)\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m)\n\u001b[1;32m 187\u001b[0m \u001b[39m# Define colors here\u001b[39;00m\n",
"\u001b[0;31mValueError\u001b[0m: style must be one of white, dark, whitegrid, darkgrid, ticks",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/Users/martinkuric/_REPOS/plotastic/HOW_TO_USE/plot_styles.ipynb Cell 11\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/martinkuric/_REPOS/plotastic/HOW_TO_USE/plot_styles.ipynb#W5sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m plst\u001b[39m.\u001b[39;49mset_style(\u001b[39m\"\u001b[39;49m\u001b[39mdf\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n",
"File \u001b[0;32m~/_REPOS/plotastic/src/plotastic/plotting/rc.py:56\u001b[0m, in \u001b[0;36mset_style\u001b[0;34m(style)\u001b[0m\n\u001b[1;32m 51\u001b[0m sns\u001b[39m.\u001b[39mset_style(style)\n\u001b[1;32m 52\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mValueError\u001b[39;00m:\n\u001b[1;32m 53\u001b[0m \u001b[39m# styles_all_s = '\\n'.join([str(s) for s in styles_all])\u001b[39;00m\n\u001b[1;32m 54\u001b[0m \u001b[39m# ### Make a pretty printed string of styles_all dictionary\u001b[39;00m\n\u001b[0;32m---> 56\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 57\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m#! Style \u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00mstyle\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m not found. Choose one from these: \u001b[39m\u001b[39m{\u001b[39;00mprint_styles()\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m\n\u001b[1;32m 58\u001b[0m )\n",
"\u001b[0;31mValueError\u001b[0m: #! Style 'df' not found. Choose one from these: None"
]
}
],
"outputs": [],
"source": [
"plst.set_style(\"paper\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Colors"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plst.set_palette([\"blue\", \"green\", \"red\"], verbose=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
158 changes: 158 additions & 0 deletions IMAGES/EXAMPLE GALLERY/example_gallery.ipynb

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions IMAGES/EXAMPLE GALLERY/example_gallery.py

This file was deleted.

Binary file added IMAGES/EXAMPLE GALLERY/qpcr1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,12 @@ classDiagram
[//]:<=========================================================================>

## Documentations 💡
1. [Quick Example: FMRI Dataset](https://github.com/markur4/plotastic/blob/main/HOW_TO_USE/quick_example_fmri.ipynb)
2. [Switch Dimensions](https://github.com/markur4/plotastic/blob/main/HOW_TO_USE/dimensions.ipynb)
1. Examples:
1. [Quick Example: FMRI Dataset](https://github.com/markur4/plotastic/blob/main/HOW_TO_USE/quick_example_fmri.ipynb)
2. [Example Gallery](https://github.com/markur4/plotastic/blob/main/IMAGES/EXAMPLE GALLERY/example_gallery.ipynb)
2. Data
1. Transform Y
2. [Set/Switch Dimensions](https://github.com/markur4/plotastic/blob/main/HOW_TO_USE/dimensions.ipynb)
3. [Plotting](https://github.com/markur4/plotastic/blob/main/HOW_TO_USE/plotting.ipynb)
1. [Legends](https://github.com/markur4/plotastic/blob/main/HOW_TO_USE/plot_legend.ipynb)
2. [MultiPlots](https://github.com/markur4/plotastic/blob/main/HOW_TO_USE/plot_multiplots.ipynb)
Expand Down
Binary file modified src/plotastic/example_data/data/qpcr.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion src/plotastic/example_data/load_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
DIMS = dict(
fmri=dict(y="signal", x="timepoint", hue="event", col="region"),
tips=dict(y="tip", x="size-cut", hue="smoker", col="sex", row="time"),
qpcr=dict(y="FC", x="gene", hue="fraction", col="class", row="method"),
qpcr=dict(y="fc", x="gene", hue="fraction", col="method", row="class"),
)


Expand Down
12 changes: 6 additions & 6 deletions src/plotastic/plotting/plotedits.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,14 @@ def edit_x_ticklabels_rotate(

def edit_grid(
self,
y_major_kws: dict = None,
y_minor_kws: dict = None,
x_major_kws: dict = None,
y_major_kws: dict = dict(),
y_minor_kws: dict = dict(),
x_major_kws: dict = dict(),
) -> "PlotEdits | DataAnalysis":
### Defaults
y_major_kwargs = dict(ls="-", linewidth=0.5, c="grey")
y_minor_kwargs = dict(ls="-", linewidth=0.2, c="grey")
x_major_kwargs = dict(ls="-", linewidth=0.3, c="grey")
y_major_kwargs = dict(ls="-", linewidth=0.5, c="grey", zorder=0)
y_minor_kwargs = dict(ls=":", linewidth=0.1, c="grey", zorder=0)
x_major_kwargs = dict(ls=":", linewidth=0.1, c="grey", zorder=0)
### Update user input
y_major_kwargs.update(**y_major_kws)
y_minor_kwargs.update(**y_minor_kws)
Expand Down
32 changes: 18 additions & 14 deletions src/plotastic/plotting/plottool.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,23 +246,27 @@ def axes_iter__ax_df(
@property #' ax11 >>> ax12 >>> ax21 >>> ax22 >>> ...
def axes_iter_leftmost_col(self) -> Generator[plt.Axes, None, None]:
"""Returns: >> ax11 >> ax21 >> ax31 >> ax41 >> ..."""
for row in self.axes_nested: #' Through rows
yield row[0] #' Leftmost ax
if self.dims.col:
for row in self.axes_nested: #' Through rows
yield row[0] #' Leftmost ax
else:
for ax in self.axes_flat:
yield ax

@property #' >> axes excluding leftmost column
def axes_iter_notleftmost_col(self) -> Generator[plt.Axes, None, None]:
"""Returns: >> axes excluding leftmost column"""
for row in self.axes_nested: #' Through rows
for ax in row[1:]: #' Through all columns except leftmost
yield ax
if self.dims.col:
for row in self.axes_nested: #' Through rows
for ax in row[1:]: #' Through all columns except leftmost
yield ax

@property #' ax31 >>> ax32 >>> ax33 >>> ax34 >>> ...
def axes_iter_lowest_row(self) -> Generator[plt.Axes, None, None]:
"""Returns: >> ax31 >> ax32 >> ax33 >> ax34 >> ..."""
if not self.dims.col is None:
for ax in self.axes_nested[
-1
]: #' Pick Last row, iterate through columns
if self.dims.col:
for ax in self.axes_nested[-1]:
#' Pick Last row, iterate through columns
yield ax
else:
yield self.axes_flat[-1] #' If no col, return last
Expand All @@ -284,7 +288,7 @@ def subplots(
y_scale: str = None,
y_scale_kws: dict = dict(),
wspace=None,
hspace=.8,
hspace=0.8,
width_ratios: list[int] = None,
height_ratios: list[int] = None,
figsize: tuple[int] = None,
Expand All @@ -295,7 +299,7 @@ def subplots(
Returns:
tuple["mpl.figure.Figure", "mpl.axes.Axes"]: matplotlib figure and axes objects
"""

# == Handle kwargs
### Adds extra kwargs depending on kwargs already present
if sharey and (wspace is None):
Expand Down Expand Up @@ -329,9 +333,9 @@ def subplots(
# squeeze=False, # !! Always return 2D array. Don't use, requires unnecessary refactoring
**KWS,
)

self.fig.subplots_adjust(hspace=1)

### Edits
### Add titles to axes to provide basic orientation
self.edit_axtitles_reset()
Expand Down Expand Up @@ -416,7 +420,7 @@ def fillaxes(
#
#
# == Fig properties ================================================

@property
def figsize(self) -> tuple[int]:
return self.fig.get_size_inches()
Expand Down
24 changes: 13 additions & 11 deletions src/plotastic/plotting/rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,36 @@
# %%
# == STYLE PAPER =======================================================
PAPER = {
# == Figure
### Figure
"figure.dpi": 200, #' Displaying figures doesn't need as much dpi as saving them
"figure.figsize": (3, 3), #' default is way too big
"figure.facecolor": "grey", #' it's easier on the eyes
# == Savefig
# "figure.facecolor": "gray", #' it's easier on the eyes
### Savefig
"savefig.dpi": 300, #' Saving figures needs more dpi
"savefig.format": "pdf",
"savefig.transparent": True,
# == Font
# "savefig.transparent": True,
"savefig.facecolor": "white",
"axes.facecolor": "white",
### Font
"font.family": "sans-serif",
"font.sans-serif": "Arial Narrow",
"font.size": FONTSIZE,
"font.weight": "bold",
# == Lines
# ## Lines
"lines.linewidth": 0.75,
# == Axes
# ## Axes
"axes.spines.right": True, #' requires argument despine=False
"axes.spines.top": True,
"axes.linewidth": 0.75,
"axes.labelweight": "bold",
"axes.titleweight": "bold",
"axes.titlepad": 5,
"axes.labelsize": FONTSIZE, #' fontsize of the x any y labels
# == Grid
"axes.grid": True,
# ## Grid
# "axes.grid": True,
"grid.linestyle": "-",
"grid.linewidth": 0.5,
# == Ticks
# ## Ticks
"ytick.left": True,
"xtick.labelsize": FONTSIZE - 1,
"ytick.labelsize": FONTSIZE - 1,
Expand All @@ -52,7 +54,7 @@
"ytick.minor.size": 2,
"xtick.major.size": 2.5,
"xtick.minor.size": 2,
# == Legend
# ## Legend
"legend.fancybox": False, #' use rounded box for legend
"legend.title_fontsize": FONTSIZE,
"legend.fontsize": FONTSIZE,
Expand Down
10 changes: 5 additions & 5 deletions tests/_DA_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@
]

dims_noempty_qpcr = [
dict(y="FC", x="gene", hue="fraction", col="class", row="method"),
dict(y="FC", x="gene", hue="fraction", col="method", row="class"),
dict(y="FC", x="gene", hue="fraction", col="class"),
dict(y="FC", x="gene", hue="fraction"),
dict(y="FC", x="gene"),
dict(y="fc", x="gene", hue="fraction", col="class", row="method"),
dict(y="fc", x="gene", hue="fraction", col="method", row="class"),
dict(y="fc", x="gene", hue="fraction", col="class"),
dict(y="fc", x="gene", hue="fraction"),
dict(y="fc", x="gene"),
]

# %%
Expand Down
18 changes: 9 additions & 9 deletions tests/annotator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,38 +147,38 @@ def test_pairwiseannotations_fmri(DF, dims, annot_kwargs):
QPCR_annot_pairwise_kwargs = [
dict(
include=["F1", "LOXL2", "SOST"],
exclude=["F2", {"IL2RG": ("F1", "F3")}],
exclude=["F2", {"MMP7": ("F1", "F3")}],
include_in_facet={
"MMPs": ["IL2RG", {"CCL20": ("F1", "F2")}],
"MMPs": ["MMP7", {"MMP9": ("F1", "F2")}],
"Bone Metabolism": ["SOST", "F2", {"TIMP1": ("F3", "F1")}],
},
exclude_in_facet={
"Wash": ["IL2RG", {"CCL20": ("F1", "F2")}],
"Wash": ["MMP7", {"MMP9": ("F1", "F2")}],
"MACS": ["SOST", {"JAK2": ("F1", "F2")}],
},
),
dict(
include=["F1", "LOXL2", "SOST"],
exclude=["F2", {"IL2RG": ("F1", "F3")}],
exclude=["F2", {"MMP7": ("F1", "F3")}],
include_in_facet={
"MMPs": ["IL2RG", {"CCL20": ("F1", "F2")}],
"MMPs": ["MMP7", {"MMP9": ("F1", "F2")}],
"Bone Metabolism": ["SOST", "F2", {"TIMP1": ("F3", "F1")}],
},
exclude_in_facet={
"Wash": ["IL2RG", {"CCL20": ("F1", "F2")}],
"Wash": ["MMP7", {"MMP9": ("F1", "F2")}],
"MACS": ["SOST", {"JAK2": ("F1", "F2")}],
},
),
dict(
include="__HUE",
exclude=["F2", {"IL2RG": ("F1", "F3")}],
exclude=["F2", {"MMP7": ("F1", "F3")}],
),
dict(
include="__X",
exclude=["F2", {"IL2RG": ("F1", "F3")}],
exclude=["F2", {"MMP7": ("F1", "F3")}],
),
dict(
include=["Vimentin", "IL2RG"],
include=["Vimentin", "MMP7"],
exclude=["FZD4"],
),
]
Expand Down

0 comments on commit a094902

Please sign in to comment.