Skip to main content

Extra visualization functions

Project description

Polyptich: easier layouting in matplotlib

import polyptich as pp
fig = pp.Figure()
ax = pp.Panel((2, 2))
ax.plot([1, 2, 3], [1, 2, 3])
fig.main.add_right(ax)

ax = pp.Panel((2, 2))
ax.plot([1, 2, 3], [1, 2, 3])
fig.main.add_right(ax)

ax = pp.Panel((2, 2))
ax.plot([1, 2, 3], [1, 2, 3])
fig.main.add_right(ax)
fig.display()

png

fig = pp.Figure()
ax1 = pp.Panel((2, 2))
ax1.plot([1, 2, 3], [1, 2, 3])
ax1.add_tag("a")

ax2 = pp.Panel((2, 2))
ax2.barh([1, 2, 3], [1, 2, 3])
ax2.add_tag("b")

ax3 = pp.Panel((2, 2))
ax3.scatter([1, 2, 3], [3, 1, 2])
ax3.add_tag("c")

ax4 = pp.Panel((2, 2))
ax4.matshow([[1, 2], [3, 4]])
ax4.add_tag("d")

title = pp.Title("Nice Hello")
legend = pp.Panel((None, 0.5))
legend.axis("off")

fig.main = title / (ax1 | ax2) / (ax3 | ax4) / legend
fig.display()

png

fig = pp.Figure()
axes = []

ax1 = pp.Panel((2, 2))
ax1.plot([1, 2, 3], [1, 2, 3])
axes.append(ax1)

ax2 = pp.Panel((2, 2))
ax2.barh([1, 2, 3], [1, 2, 3])
axes.append(ax2)

ax3 = pp.Panel((2, 2))
ax3.scatter([1, 2, 3], [3, 1, 2])
axes.append(ax3)

ax4 = pp.Panel((2, 2))
ax4.matshow([[1, 2], [3, 4]])
axes.append(ax4)

fig.main = pp.Wrap(axes, ncol = 3)
fig.display()

png

import pandas as pd
import numpy as np
data = pd.DataFrame(np.random.randn(1000, 20))
obs = pd.DataFrame({
    "celltype":["Kupffer cells"] * 300 + ["Stellate cells"] * 300 + ["Stupid cells"] * 400
})
celltypes = pd.DataFrame.from_dict({
    "Kupffer cells": {"color": "red"},
    "Stellate cells": {"color": "blue"},
    "Stupid cells": {"color": "green"}
}, orient = "index")
var = pd.DataFrame(index = [f"gene_{i}" for i in range(20)])
var["module"] = ["module_1"] * 5 + ["module_2"] * 5 + ["module_3"] * 10
data.columns = var.index
modules = pd.DataFrame({
    "module":["module_1", "module_2", "module_3"],
    "color":["red", "blue", "green"]
}).set_index("module")
var["color"] = modules.loc[var["module"]]["color"].values
fig = pp.Figure(pp.Grid(padding_height = 0., padding_width = 0.))

row_layout = pp.heatmap.layouts.Broken(var["module"].astype("category"))
col_layout = pp.heatmap.layouts.Broken(obs["celltype"].astype("category"))

main_heatmap = fig.main.add(pp.heatmap.Heatmap(data, row_layout = row_layout, col_layout = col_layout))
heading = fig.main.add_above(pp.heatmap.heading.HeadingTop(obs, celltypes, col_layout))

ticks = fig.main.add_left(pp.heatmap.ticks.TicksLeft(var, row_layout), row = main_heatmap)
heading = fig.main.add_right(pp.heatmap.heading.HeadingRight(var, modules, row_layout), row = main_heatmap)

fig.display()

png

fig = pp.Figure(pp.Grid(padding_height = 0., padding_width = 0.))

row_layout = pp.heatmap.layouts.Broken(var["module"].astype("category"))
col_layout = pp.heatmap.layouts.Broken(obs["celltype"].astype("category"))

main_heatmap = fig.main.add(pp.heatmap.Heatmap(data, row_layout = row_layout, col_layout = col_layout))
heading = fig.main.add_above(pp.heatmap.heading.HeadingTop(obs, celltypes, col_layout))

ticks = fig.main.add_right(pp.heatmap.ticks.TicksRight(var, row_layout), row = main_heatmap)
heading = fig.main.add_left(pp.heatmap.heading.HeadingLeft(var, modules, row_layout), row = main_heatmap)

fig.display()

png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polyptich-0.0.14.tar.gz (1.1 MB view details)

Uploaded Source

File details

Details for the file polyptich-0.0.14.tar.gz.

File metadata

  • Download URL: polyptich-0.0.14.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for polyptich-0.0.14.tar.gz
Algorithm Hash digest
SHA256 c06972b020077e01b050a22133bfbd7f06c08c7a246527007f7f640de6d37925
MD5 71fe6f9d7e27661132a973a4dc224ffe
BLAKE2b-256 af4b7127c892896681f5004db5e6213aae9fa8cf18cda794992519b04e5b5933

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page