zl程序教程

您现在的位置是:首页 >  其他

当前栏目

跟着PNAS学作图:python做花瓣图(flower plot)展示草莓泛基因组的数据

2023-04-18 16:25:41 时间

论文

Evolutionary history and pan-genome dynamics of strawberry (Fragaria spp.)

(schloarscope这个插件变成收费的插件了)

本地存储 草莓PNAS.pdf

今天的推文我们试着重复一下论文中的figure1C

如何用R语言的ggplot2做我现在也有了思路,但是找资料的时候发现了一个python的现成的模块

github的主页是 https://github.com/MrTomRod/flower-plot

主页上写的是 A Python 3.9+ function that makes flower plots.,我电脑上安装的是3.8.3。我先试试能不能行

首先是安装

pip install git+https://github.com/MrTomRod/flower-plot.git

运行安装命令没有问题

接下来试试他的例子

遇到报错

瞎猜是python版本的问题,我们换一个版本试试

新建一个虚拟环境

conda create -n flower_plot python=3.9

激活环境

conda activate flower_plot

安装flower_plot

pip install git+https://github.com/MrTomRod/flower-plot.git

这里遇到一个问题是虚拟环境里是python 3.9,如何在使用jupyter lab的时候调用这个虚拟环境还是用python3.9,这个还是没有搞定,只能换一个annconda是自带python3.9的了

用python3.9运行出了结果

接下来我们用PNAS文章里草莓的数据试试

首先是构造数据

genome_to_data = {
    'F. daltoniana': {'color': "#f63c50", 'shell': 6882, 'unique': 188},
    'F. iinumae': {'color': "#ff8e54", 'shell': 5480, 'unique': 95},
    'F. mandschurica': {'color': "#ffe087", 'shell': 5127, 'unique': 237},
    'F. nilgerrensis': {'color': "#ffffbe", 'shell': 5527, 'unique': 179},
    'F. pentaphylla': {'color': "#e1f594", 'shell': 3760, 'unique': 187},
    'F. vesca': {'color': "#77d793", 'shell': 6973, 'unique': 158},
    'F. viridis': {'color': "#0088bf", 'shell': 5995, 'unique': 213},
}

画图

import matplotlib.pyplot as plt
from flower_plot import flower_plot

flower_plot(genome_to_data=genome_to_data, 
            n_core=10665,
           shell_color="#ebccea",
           core_color="red",
           alpha=1)
plt.tight_layout()
plt.savefig("1.pdf")

这个是最终的结果

但是拉丁名怎么设置斜体,字体修改成新罗马暂时还没有找到参数设置,只能出图后手动编辑图片了

调整细节不如ggplot2好用,争取研究下ggplot2的实现代码