matlab plot不均匀间隔,matplotlib如何绘制间隔为2^n的不均匀图形?

使用matplotlib创建不均匀间隔的图形,重点在于设置自定义的刻度和标签。示例代码展示了如何从1到128的平方函数中选取2^n的点进行绘制,实现间隔为2的幂次的不均匀分布图形。
摘要由CSDN通过智能技术生成

如果我的意见不够清楚,请你问。:)from matplotlib import pyplot as plt

# Instanciating my lists...

f = lambda x:x**2

x = [nb for nb in range(1, 129)]

y = [f(nb) for nb in x]

# New values you want to plot, with linear spacing.

indexes_to_keep = [1, 2, 4, 8, 16, 32, 64, 128]

y_to_use = [y[nb - 1] for nb in indexes_to_keep]

# First plot that shows the 128 points as a whole.

fig = plt.figure(figsize=(10, 5.4))

ax1 = fig.add_subplot(121)

ax1.plot(x, y)

ax1.set_title('Former values')

# Second plot that shows only the indexes you wish to keep.

ax2 = fig.add_subplot(122)

# my_ticks = [1, 2, 3, 4, 5, 6, 7]

# meaning : my_ticks will be linear values.

my_ticks = [i for i in range(len(indexes_to_keep))]

# We set the ticks we want to show, meaning : all our

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值