r语言 断轴 画图_【教程】使用R语言画lineage though time plot (LTT)

#load ape package

library('ape')

#read a selected trees file; select nexus trees file in pumped

window, and name it as treesForLTT

read.nexus(choose.files())->treesForLTT

#read one tree (the best tree)

read.nexus(choose.files())->oneTreeForLTT

#check how many trees are there in treesForLTT

treesForLTT

#burn some trees.30% of total trees is acceptable. Set your

own number.

treesForLTT[3000:10001]->fineTreesForLTT

#It could be slow if there are too many trees. Discard more

trees will help.

#预画图

#draw LTT plot of all fine trees.

mltt.plot(fineTreesForLTT, legend = F, dcol = F, ylab =

'Number of Lineages', xlab = 'Time')

#add the best tree

ltt.lines(oneTreeForLTT, col = 'red', lwd = 2)

得到图片如下:

图太长了。因为一些树左边的枝太长太长。另外,黑色太厚实了,不好看。

#重写mltt.plot函数并修图

#添加了两个参数,xrange限制x轴的范围;owncol指定线的颜色。

#the x axis is so long. Has to be black in mltt.plot?

#Don't know how to change xlim and line color in mltt. So

stupid am I.

#so rewrite function mltt.plot into Own.mltt.plot</

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Matplotlib轴是指在绘制图表时,当某些变量的数量级远大于其他变量时,为了将它们放在同一张图中,需要对坐标轴进行截。Matplotlib没有直接提供这个功能,但可以通过一些技巧实现。其中一种方法是使用mpl_toolkits.axes_grid1库中的make_axes_locatable函数来创建一个新的坐标轴,并将其放置在原始坐标轴的位置上,然后在新的坐标轴上绘制数据。这样就可以实现轴的效果。 举个例子,如果我们要绘制一组数据,其中有一个变量的数量级远大于其他变量,我们可以使用Matplotlib的轴功能来将其放在同一张图中。具体步骤如下: ```python import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable # 生成数据 x = [1, 2, 3, 4, 5] y1 = [10, 20, 30, 40, 50] y2 = [1000, 2000, 3000, 4000, 5000] # 创建布和子图 fig, ax = plt.subplots() # 绘制数据 ax.plot(x, y1) ax.set_ylabel('y1') # 创建新的坐标轴 divider = make_axes_locatable(ax) ax2 = divider.append_axes("bottom", size="30%", pad=0.1) # 绘制数据 ax2.plot(x, y2) ax2.set_ylabel('y2') # 设置坐标轴范围 ax.set_ylim(0, 60) ax2.set_ylim(900, 5500) # 显示图形 plt.show() ``` 在这个例子中,我们使用make_axes_locatable函数创建了一个新的坐标轴,并将其放置在原始坐标轴的下方。然后在新的坐标轴上绘制了另一组数据。最后,我们通过设置坐标轴的范围来实现轴的效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值