python怎么在一张图上画多条折线_如何在python中直观地堆叠多个折线图?

1586010002-jmsa.png

I was having trouble creating a plot I need which has multiple line graphs.

What I want is a way to graph each of these above the other (say one has a baseline of y=5 I want the next to have a baseline of y=10) and also each of these graphs must block the one above it.

So this will inevitably look like the cover to Joy Divisions Unknown Pleasures here:

http://cococubed.asu.edu/images/unknown_pleasures/unknown_pleasures.jpg

Except inverted colors and I also would like an answer that utilizes python or numpy or matplotlib.

解决方案

Here's one way. The key point is to use fill_between function and offset each plotted line with some margin (i*2 in this case). Also, plotting has to start from the top, hence the [::-1] in the arange slice.

t=linspace(-2*pi, 2*pi, 1000)

for i in arange(1, pi, 0.01)[::-1]:

left = exp(-(t + (i - 1) * 2*pi)**2) * cos(t * i)**2 - 1

right = exp(-(t - (i - 1) * 2*pi)**2) * cos(t * i)**2 - 1

vertical_offset = i*2

fill_between(t, vertical_offset + left + right, facecolor='white')

7Xow1eL.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值