我试图找出如何以数据单位绘制宽度的线条.例如,在下面的代码片段中,我希望宽度为80的线的水平部分始终从y = -40延伸到y = + 40标记,即使坐标系的限制也保持这种状态更改.有没有办法用matplotlib中的Line2D对象来实现这个目的?任何其他方式获得类似的效果?
from pylab import figure, gca, Line2D
figure()
ax = gca()
ax.set_xlim(-50, 50)
ax.set_ylim(-75, 75)
ax.add_line(Line2D([-50, 0, 50], [-50, 0, 0], linewidth=80))
ax.grid()
Run Code Online (Sandbox Code Playgroud)

你可以使用fill_between:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_xlim(-50, 50)
ax.set_ylim(-75, 75)
x = [-50, 0, 50]
y = np.array([-50, 0, 0])
ax.fill_between(x,y-30,y+30)
ax.grid()
plt.show()
Run Code Online (Sandbox Code Playgroud)
产量

但不像生成的线
ax.add_line(Line2D([-50, 0, 50], [-50, 0, 0], linewidth=80))
Run Code Online (Sandbox Code Playgroud)
线的垂直厚度在数据坐标中始终是恒定的.
另请参阅文档链接.
| 归档时间: |
|
| 查看次数: |
3458 次 |
| 最近记录: |