Skip to main content

A python project for making logos in plotly.

Project description

Title

A python project for making logos in plotly similar to logomaker. plotlylogomaker is inspired by the work of Kevin Kovalchik.

Example

Code
from pathlib import Path

import numpy as np
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots

from plotlylogomaker.color import DMS_COLOR_SCHEME
from plotlylogomaker.logo import Logo, add_logo

AMINO_ACIDS = (
    "A",
    "C",
    "D",
    "E",
    "F",
    "G",
    "H",
    "I",
    "K",
    "L",
    "M",
    "N",
    "P",
    "Q",
    "R",
    "S",
    "T",
    "V",
    "W",
    "Y",
)
PLOTLYLOGOMAKER_PATH = Path("docs")

np.random.seed(42)


def mock_logo(positions: int, legend: bool, adjustment: float = 0.0) -> Logo:
    """Mock function to create a logo with a specified number of positions."""
    raw = np.random.rand(20, positions)
    frequencies = pd.DataFrame(raw, index=AMINO_ACIDS)
    normalized = frequencies.div(frequencies.sum(axis=0), axis=1).T
    normalized = normalized - adjustment
    return Logo(df=normalized, legend=legend, color_scheme=DMS_COLOR_SCHEME, hover=True)


logo1 = mock_logo(8, legend=True)
logo2 = mock_logo(6, legend=False)
logo3 = mock_logo(5, legend=True, adjustment=0.05)

# single plot figure
fig: go.Figure = go.Figure()
add_logo(logo1, fig)
fig.update_layout(height=800)
fig.write_image(PLOTLYLOGOMAKER_PATH / "single_plot_example.svg")


# 1x2 subplot figure
fig = make_subplots(rows=1, cols=2, vertical_spacing=0.15, horizontal_spacing=0.05)
add_logo(logo1, fig, row=1, col=1)
add_logo(logo2, fig, row=1, col=2)
fig.update_layout(height=800)
fig.write_image(PLOTLYLOGOMAKER_PATH / "subplot_example.svg")

# single plot figure illustrating negative values.
fig = go.Figure()
add_logo(logo3, fig)
fig.update_layout(height=800)
fig.write_image(PLOTLYLOGOMAKER_PATH / "singleplot_negative_frequencies.svg")
Single Plot Logo example

Single Plot Logo example

Subplot Logo example

Subplot Logo example

Single Plot Logo with negative frequencies example

Single Plot Logo with negative frequencies example

Color Schemes

Three color schemes are defined in plotlylogomaker.color:

  • DMS
  • Chemical Groups
  • Nucleotides

Users can define custom color schemes via the plotlylogomaker.color.ColorScheme class, where alphabet letters serve as the keys.

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

plotlylogomaker-0.1.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plotlylogomaker-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file plotlylogomaker-0.1.0.tar.gz.

File metadata

  • Download URL: plotlylogomaker-0.1.0.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for plotlylogomaker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2c58cd5a8b8cabd0c001e3a10e6ee7f7964a9d08de088ec3c76d06208435b51a
MD5 4b197b131dd069c23599ec41e1b89190
BLAKE2b-256 610e5b3ba0afdd4b43a1c70255c2d1a0e4a5a8a8611c6bbed816bf31a8124df2

See more details on using hashes here.

File details

Details for the file plotlylogomaker-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for plotlylogomaker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ecc744bb88cf81fd6c4f402c31b3d7c06d88751143e9a8520e0a5a642677685
MD5 1bfec5755aa8ec50e9bac332717869f9
BLAKE2b-256 bf1d89a903dfec969d48dfae72a7c06b6b943ff323c098efaa20c3e778dc4934

See more details on using hashes here.

Supported by

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