Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title Italics #35

Closed
gbouras13 opened this issue Aug 23, 2023 · 2 comments
Closed

Title Italics #35

gbouras13 opened this issue Aug 23, 2023 · 2 comments
Labels
question Further information is requested

Comments

@gbouras13
Copy link

Hi @moshi4 ,

Question about italicising the title.

I have code like this in my program pharokka implementing pyCirclize.

    # get only to range of gff - as by default gbk takes all contigs, gff only the first
    gbk = Genbank(gbk_file)

    # instantiate circos
    circos = Circos(sectors={gbk.name: gbk.range_size})

   # example plot name
   plot_title = "Staphylococcus Phage one"

    # title if not blank
    circos.text(plot_title, size=int(title_size), r=190)

By default, the plot_title will always plot the title without italics.

However, for this application, it would be useful if I could italicise certain words (in this case, "Staphylococcus Phage one").

There there an easy way to do this that you know of?

George

@moshi4
Copy link
Owner

moshi4 commented Aug 23, 2023

Hi @gbouras13,

pyCirclize is a matplotlib-based library, so you can basically take advantage of matplotlib text styles.
As far as I know, in matplotlib you can set italic text like below.

from pycirclize import Circos
from pycirclize.utils import fetch_genbank_by_accid
from pycirclize.parser import Genbank

# Download `NC_002483` E.coli plasmid genbank
gbk_fetch_data = fetch_genbank_by_accid("NC_002483")
gbk = Genbank(gbk_fetch_data)

# Initialize Circos instance with genome size
circos = Circos(sectors={gbk.name: gbk.range_size})
circos.rect(r_lim=(90, 100), fc="lightgrey", ec="none", alpha=0.5)
sector = circos.sectors[0]

# Plot forward strand CDS
f_cds_track = sector.add_track((95, 100))
f_cds_feats = gbk.extract_features("CDS", target_strand=1)
f_cds_track.genomic_features(f_cds_feats, plotstyle="arrow", fc="salmon", lw=0.5)

# Plot reverse strand CDS
r_cds_track = sector.add_track((90, 95))
r_cds_feats = gbk.extract_features("CDS", target_strand=-1)
r_cds_track.genomic_features(r_cds_feats, plotstyle="arrow", fc="skyblue", lw=0.5)

# Plot title with all italic (use style="italic")
circos.text("Escherichia coli K-12 plasmid F (all italic)", size=14, r=10, deg=0, style="italic")

# Plot title with partial italic (use ${text}$)
circos.text("${Escherichia}$ ${coli}$ K-12 plasmid F (partial italic)", size=14, r=10, deg=180)

circos.savefig("result.png")

result.png

result

Reference:
https://stackoverflow.com/questions/8376335/styling-part-of-label-in-legend-in-matplotlib

@gbouras13
Copy link
Author

This is legendary @moshi4. Works a treat even when I pass the title from a command line argument. Thanks so much once again.

George

@moshi4 moshi4 added the question Further information is requested label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants