Skip to content

Commit

Permalink
Add pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Milk committed Sep 8, 2024
1 parent d3ad0a7 commit a318de5
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 100 deletions.
2 changes: 1 addition & 1 deletion docs/examples/Gallery/plot_oil_well.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"150-199 °C (Light saute)",
"<150 °C (Dressings)",
]
cb.hsplit(labels=oils["cooking conditions"], order=order)
cb.group_rows(oils["cooking conditions"], order=order)
cb.add_left(conditions, pad=0.1)
cb.add_dendrogram(
"left", add_meta=False, colors=colors, linewidth=1.5, size=0.5, pad=0.02
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/Gallery/plot_pbmc3k.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
h.add_left(cell_types)
h.add_bottom(gene_names)

h.hsplit(labels=cell_cat, order=["Lymphoid", "Myeloid"])
h.group_rows(cell_cat, order=["Lymphoid", "Myeloid"])
h.add_left(mp.Chunk(["Lymphoid", "Myeloid"], ["#33A6B8", "#B481BB"]), pad=0.05)
h.add_dendrogram("left", colors=["#33A6B8", "#B481BB"])
h.add_dendrogram("bottom")
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/Gallery/plot_sc_multiomics.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"title": "% expression in group",
},
)
gene_profile.hsplit(labels=lineage_cells, order=lineage)
gene_profile.group_rows(lineage_cells, order=lineage)
gene_profile.add_left(ma.plotter.Chunk(lineage, lineage_colors, padding=10))
gene_profile.add_dendrogram(
"left",
Expand Down Expand Up @@ -103,7 +103,7 @@
"title": "% expression in group",
},
)
protein_profile.hsplit(labels=lineage_cells, order=lineage)
protein_profile.group_rows(lineage_cells, order=lineage)
protein_profile.add_bottom(
ma.plotter.Labels(marker_names, color="#E36414", align="bottom", padding=10)
)
Expand Down
22 changes: 17 additions & 5 deletions docs/examples/Gallery/plot_tiobe_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@
# ---------

data = {
"Programming Language": ["Python", "C++", "C", "Java", "C#", "JavaScript",
"Go", "Visual Basic", "Fortran", "SQL"],
"Programming Language": [
"Python",
"C++",
"C",
"Java",
"C#",
"JavaScript",
"Go",
"Visual Basic",
"Fortran",
"SQL",
],
"Ratings": [16.12, 10.34, 9.48, 8.59, 6.72, 3.79, 2.19, 2.08, 2.05, 2.04],
}
data = pd.DataFrame(data).set_index("Programming Language")
Expand All @@ -50,8 +60,10 @@
# Plot
c = ma.ZeroWidth(5)
c.add_right(mp.Image([images[lang] for lang in data.index]))
c.add_left(mp.Labels(data.index, fontweight=600), pad=.1)
c.add_right(mp.Numbers(data['Ratings'], color="#009FBD", label="Rating"), pad=.1)
c.add_title("https://www.tiobe.com/tiobe-index/", align="left", fontsize=10, fontstyle="italic")
c.add_left(mp.Labels(data.index, fontweight=600), pad=0.1)
c.add_right(mp.Numbers(data["Ratings"], color="#009FBD", label="Rating"), pad=0.1)
c.add_title(
"https://www.tiobe.com/tiobe-index/", align="left", fontsize=10, fontstyle="italic"
)
c.add_title("TIOBE Index July 2024", align="left", fontweight=600)
c.render()
11 changes: 9 additions & 2 deletions docs/examples/Gallery/plot_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Track Plot
==========
"""

import marsilea as ma
import marsilea.plotter as mp

Expand Down Expand Up @@ -42,8 +43,14 @@
name = f"{cond}{enz}"
color = colors[enz]
canvas.add_bottom(
mp.Area(track, color=color, add_outline=False, alpha=1,
label=cond, label_loc="right"),
mp.Area(
track,
color=color,
add_outline=False,
alpha=1,
label=cond,
label_loc="right",
),
size=TRACK_HEIGHT,
pad=TRACK_PAD,
name=name,
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/Plotters/plot_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
h = ma.Heatmap(matrix)
chunk = ["C1", "C2", "C3", "C4"]
labels = np.random.choice(chunk, size=20)
h.hsplit(labels=labels, order=chunk)
h.group_rows(labels, order=chunk)
h.add_right(Chunk(chunk, bordercolor="gray"), pad=0.1)
h.add_dendrogram("left")
h.render()
5 changes: 2 additions & 3 deletions docs/examples/Plotters/plot_emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

# %%

from marsilea.plotter import Emoji

# %%
import numpy as np
import matplotlib.pyplot as plt

from marsilea.plotter import Emoji

_, ax = plt.subplots()
Emoji("😆😆🤣😂😉😇🐍🦀🦄").render(ax)
2 changes: 1 addition & 1 deletion docs/examples/Plotters/plot_fixed_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
h = ma.Heatmap(matrix)
chunk = ["C1", "C2-1", "C2-2", "C4"]
labels = np.random.choice(chunk, size=20)
h.hsplit(labels=labels, order=chunk)
h.group_rows(labels, order=chunk)
h.add_right(FixedChunk(chunk, bordercolor="gray"), pad=0.1)
h.add_right(
FixedChunk(
Expand Down
18 changes: 10 additions & 8 deletions docs/examples/Plotters/plot_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@

# %%

from marsilea.plotter import Image

# %%
import numpy as np
import matplotlib.pyplot as plt

from marsilea.plotter import Image

_, ax = plt.subplots()
Image([
"https://www.iconfinder.com/icons/4375050/download/png/512",
"https://www.iconfinder.com/icons/8666426/download/png/512",
"https://www.iconfinder.com/icons/652581/download/png/512"
], align="right").render(ax)
Image(
[
"https://www.iconfinder.com/icons/4375050/download/png/512",
"https://www.iconfinder.com/icons/8666426/download/png/512",
"https://www.iconfinder.com/icons/652581/download/png/512",
],
align="right",
).render(ax)
6 changes: 3 additions & 3 deletions docs/examples/Plotters/plot_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

_, ax = plt.subplots(figsize=(0.5, 6))
data = np.random.randint(0, 10, 30)
l = Labels(data)
l.set_side("right")
l.render(ax)
labels = Labels(data)
labels.set_side("right")
labels.render(ax)
10 changes: 8 additions & 2 deletions docs/how_to/legends/plot_custom_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@

# %%
import numpy as np

import marsilea as ma
from marsilea.plotter import ColorMesh, Colors

data = np.random.randint(0, 10, (10, 10))


# %%
from legendkit import cat_legend
def my_legend(): return cat_legend(labels=["my super legend"], colors=["lightblue"], title="My Legend")


def my_legend():
return cat_legend(
labels=["my super legend"], colors=["lightblue"], title="My Legend"
)


h = ma.Heatmap(data, width=3, height=3)
h.custom_legend(my_legend)
Expand Down
117 changes: 70 additions & 47 deletions docs/source/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,124 +9,147 @@ Declarative API Cheat Sheet

.. list-table::
:header-rows: 1
:widths: 10 50 50

* - Operator
- Description
- Showcase
- Example

* - :meth:`~marsilea.base.WhiteBoard.add_layer`
- Add a plotter to main canvas.

* - | :meth:`~marsilea.base.WhiteBoard.add_layer`
| Add a plotter to main canvas.
- .. image:: ../img/api_add_layer.png
- .. code-block:: python

wb.add_layer(ColorMesh(data))

* - :meth:`~marsilea.base.WhiteBoard.add_left`
- Add to the **left-side** of main canvas.
* - | :meth:`~marsilea.base.WhiteBoard.add_left`
| Add to the **left-side** of main canvas.
- .. image:: ../img/api_add_left.png
- .. code-block:: python

wb.add_left(Numbers(data),
size=1, pad=.1,
name='left-plot')

* - :meth:`~marsilea.base.WhiteBoard.add_right`
- Add a plotter to the **right-side** of main canvas.
* - | :meth:`~marsilea.base.WhiteBoard.add_right`
| Add a plotter to the **right-side** of main canvas.
- .. image:: ../img/api_add_right.png
- .. code-block:: python

wb.add_right(Numbers(data))

* - :meth:`~marsilea.base.WhiteBoard.add_top`
- Add a plotter to the **top-side** of main canvas.
* - | :meth:`~marsilea.base.WhiteBoard.add_top`
| Add a plotter to the **top-side** of main canvas.
- .. image:: ../img/api_add_top.png
- .. code-block:: python

wb.add_top(Numbers(data))

* - :meth:`~marsilea.base.WhiteBoard.add_bottom`
- Add a plotter to the **bottom-side** of main canvas.
* - | :meth:`~marsilea.base.WhiteBoard.add_bottom`
| Add a plotter to the **bottom-side** of main canvas.
- .. image:: ../img/api_add_bottom.png
- .. code-block:: python

wb.add_bottom(Numbers(data))

* - :meth:`~marsilea.base.WhiteBoard.add_title`
- Add titles to the plot.
* - | :meth:`~marsilea.base.WhiteBoard.add_title`
| Add titles to the plot.
- .. image:: ../img/api_add_title.png
- .. code-block:: python

wb.add_title(top='Top Title', bottom='Bottom Title'
left='Left Title', right='Right Title')
wb.add_title(top='Top', bottom='Bottom'
left='Left', right='Right')

* - :meth:`~marsilea.base.ClusterBoard.add_dendrogram`
- Add a dendrogram to the plot, only available to ClusterBoard.
* - | :meth:`~marsilea.base.ClusterBoard.add_dendrogram`
| Add a dendrogram to the plot, only available to ClusterBoard.
- .. image:: ../img/api_add_dendrogram.png
- .. code-block:: python

cb.add_dendrogram("left", data)
cb.add_dendrogram("right")

* - :meth:`~marsilea.base.ClusterBoard.group_cols`
- Split the main canvas horizontally, only available to ClusterBoard.
* - | :meth:`~marsilea.base.ClusterBoard.group_cols`
| Split the main canvas vertically by labeling columns, only available to ClusterBoard.
- .. image:: ../img/api_group_cols.png
- .. code-block:: python

cb.group_cols(labels=[1, 1, 2, 2], order=[2, 1])
cb.group_cols(list("11223"))

* - :meth:`~marsilea.base.ClusterBoard.group_rows`
- Split the main canvas vertically, only available to ClusterBoard.
* - | :meth:`~marsilea.base.ClusterBoard.group_rows`
| Split the main canvas horizontally by labeling rows, only available to ClusterBoard.
- .. image:: ../img/api_group_rows.png
- .. code-block:: python

cb.group_rows(labels=[1, 1, 2, 2], order=[2, 1])
cb.group_rows(list("11223"))

* - :meth:`~marsilea.base.ClusterBoard.cut_cols`
- Split the main canvas horizontally, only available to ClusterBoard.
* - | :meth:`~marsilea.base.ClusterBoard.cut_cols`
| Split the main canvas vertically by positions, only available to ClusterBoard.
- .. image:: ../img/api_cut_cols.png
- .. code-block:: python

cb.cut_cols([5])
cb.cut_cols([2, 4])

* - :meth:`~marsilea.base.ClusterBoard.cut_rows`
- Split the main canvas vertically, only available to ClusterBoard.
* - | :meth:`~marsilea.base.ClusterBoard.cut_rows`
| Split the main canvas horizontally by positions, only available to ClusterBoard.
- .. image:: ../img/api_cut_rows.png
- .. code-block:: python

cb.cut_rows([5])
cb.cut_rows([2, 4])

* - :meth:`~marsilea.base.LegendMaker.add_legends`
- Add legends to the plots.
* - | :meth:`~marsilea.base.LegendMaker.add_legends`
| Add legends to the plots.
- .. image:: ../img/api_add_legends.png
- .. code-block:: python

wb.add_legends()

* - :meth:`~marsilea.base.WhiteBoard.add_canvas`
- Add a plotter to a chosen side of main plot.
* - | :meth:`~marsilea.base.WhiteBoard.add_canvas`
| Add a empty canvas to a chosen side of main plot.
- .. image:: ../img/api_add_canvas.png
- .. code-block:: python

wb.add_canvas("right", Numbers(data))
wb.add_canvas("right")

* - :meth:`~marsilea.base.WhiteBoard.add_pad`
- Add white space between plot.
* - | :meth:`~marsilea.base.WhiteBoard.add_pad`
| Add white space between plot.
- ---
- .. code-block:: python

wb.add_pad("right", 1)

* - :meth:`~marsilea.base.WhiteBoard.set_margin`
- Add white space surrounding the figure.
* - | :meth:`~marsilea.base.WhiteBoard.set_margin`
| Add white space surrounding the figure.
- ---
- .. code-block:: python

wb.set_margin(1)

* - :meth:`~marsilea.base.WhiteBoard.render`
- Render the plot.

* - | :meth:`~marsilea.base.WhiteBoard.render`
| Render the plot.
- ---
- .. code-block:: python

wb.render()

* - :meth:`~marsilea.base.WhiteBoard.save`
- Save the plot to a file.

* - | :meth:`~marsilea.base.WhiteBoard.save`
| Save the plot to a file.
- ---
- .. code-block:: python

wb.save("output.png", dpi=300)

* - :code:`+`
- Two canvas side by side, number will be added as white space
* - | :code:`+`
| Two canvas side by side, number will be added as white space
- .. image:: ../img/api_concatenate_plus.png
- .. code-block:: python

(wb1 + 1 + wb2).render()

* - :code:`/`
- Two canvas top and bottom, number will be added as white space
* - | :code:`/`
| Two canvas top and bottom, number will be added as white space
- .. image:: ../img/api_concatenate_divide.png
- .. code-block:: python

(wb1 / 1 / wb2).render()
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorial/axes-level.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ to retrieve the named axes.
:context: close-figs

>>> h = ma.Heatmap(data, linewidth=1)
>>> h.hsplit(cut=[5])
>>> h.cut_rows(cut=[5])
>>> bar = ma.plotter.Numbers(np.arange(20))
>>> h.add_right(bar, name="My Bar")
>>> h.render()
Expand Down
Loading

0 comments on commit a318de5

Please sign in to comment.