java中线段宽度怎么设置_matplotlib使用list更改线段上的线宽

基本上,您有两种选择 .

使用 LineCollection . 在这种情况下,您的线宽将以点为单位,并且每个线段的线宽将保持不变 .

使用多边形(最简单的是 fill_between ,但对于复杂的曲线,您可能需要直接创建它) . 在这种情况下,您的线宽将以数据单位表示,并且会在您的线条中的每个线段之间线性变化 .

以下是两者的示例:

行集合示例

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.collections import LineCollection

np.random.seed(1977)

x = np.arange(10)

y = np.cos(x / np.pi)

width = 20 * np.random.random(x.shape)

# Create the line collection. Widths are in _points_! A line collection

# consists of a series of segments, so we need to reformat the data slightly.

coords = zip(x, y)

lines = [(start, end) for start, end in zip(coords[:-1], coords[1:])]

lines = LineCollection(lines, linewidths=width)

fig, ax = plt.subplots()

ax.add_collection(lines)

ax.autoscale()

plt.show()

2c9f7ab8-8c8e-4226-9038-6b78dac027b2.png

多边形示例:

import numpy as np

import matplotlib.pyplot as plt

np.random.seed(1977)

x = np.arange(10)

y = np.cos(x / np.pi)

width = 0.5 * np.random.random(x.shape)

fig, ax = plt.subplots()

ax.fill_between(x, y - width/2, y + width/2)

plt.show()

fa40853b-32c3-4a43-b1e4-362045633720.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值