dax*_*ax5 1 python axis matplotlib scale
只想绘制一个包含50个(实际上是51个)元素的列表:从0到50的列表索引应表示x轴上0到10米的米,而每个其他元素的索引增加0.2米.例:
list = [2.5, 3, 1.5, ... , 7, 9]
len(list)
>>50
Run Code Online (Sandbox Code Playgroud)
我想x轴绘制从0到10米,即(x,y)==(0,2.5),(0.2,3),(0.4,1.5),...,(9.8,7), (10,9)
相反,列表显然是在0到50的x范围内绘制的.任何想法如何解决问题?谢谢!
我会避免命名列表对象list.它混淆了命名空间.但尝试类似的东西
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x = np.arange(0, 10, 0.2)
y = [2.5, 3, 1.5, ... , 7, 9]
ax.plot(x, y)
plt.show()
Run Code Online (Sandbox Code Playgroud)
它在x轴上创建一个点列表,该列表出现在0.2使用的倍数np.arange处,matplotlib将在其中绘制y值.Numpy是一个用于轻松创建和操作向量,矩阵和数组的库,尤其是当它们非常大时.
编辑:
fig.add_subplot(N_row,N_col,plot_number)是使用matplotlib进行绘图的面向对象方法.如果要将多个子图添加到同一图中,这将非常有用.例如,
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
Run Code Online (Sandbox Code Playgroud)
在同一个图中添加了两个子图fig.它们将以两排排列在另一排之上.ax2是底部子图.查看相关帖子了解更多信息.
要更改实际的x刻度和刻度标签,请使用类似的内容
ax.set_xticks(np.arange(0, 10, 0.5))
ax.set_xticklabels(np.arange(0, 10, 0.5))
# This second line is kind of redundant but it's useful if you want
# to format the ticks different than just plain floats.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17469 次 |
| 最近记录: |