python - matplotlib 中的透明 axes.axhline?

标签 python matplotlib

我试图在我的坐标轴上添加一条水平线来标记一个重要的 y 值,所以我正在使用:

fig = Figure(figsize=(5, 5))
ax = fig.add_axes((0.2, 0.2, 0.6, 0.6))
ax.plot(...)
ax.axhline(100000, xmin=0, xmax=1, linewidth=0.3, color=(0, 0, 0, 0.75))
canvas = FigureCanvasAgg(fig)
canvas.print_figure("chart.pdf", dpi=300)

但是我遇到了一些问题:

  • 线宽是什么单位?积分?
  • 这条线似乎不符合我的颜色的 alpha 值。 a = 0时透明,a > 0时不透明,没有半透明。这是错误还是我做错了什么?

我正在使用:

Mac OSX 10.6.7、Python 2.7、matplotlib 1.0.1、numpy 1.5.1

最佳答案

线宽以磅为单位。

使用 matplotlib 1.0+ 时,透明度对我来说效果很好。这是我用来测试的代码:

from matplotlib import pyplot as plt
import numpy as np

x = np.arange(0,10,.1)
y = np.sin(x)
plt.plot(x,y)
ax = plt.gca()
ax.axhline(.4, xmin=0, xmax=1, linewidth=0.3, color=(0, 0, 0, 0.75))
plt.show()

您要绘制 axhline 的情节是什么?可能与特定类型的情节有冲突。

关于python - matplotlib 中的透明 axes.axhline?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5574641/

相关文章:

python - 在 python 2.7 中使用 PI

python - 为什么在 Python3.0 中将 cmp 参数从 sort/sorted 中删除?

python - 如何在 python 数据框中绘制一系列值的特定颜色?

python - matplotlib 和 unicode 字符

python - 是否可以创建一个类,其每个实例都有不同的类型?

python - 拟合模型时出错

javascript - 如何在 JupyterLab 中通过 JavaScript 评估文档上下文中的 Python 代码?

使用 Pandas 数据读取器进行 Python 回归建模

python - 在条形图动画的每次迭代中添加新的数据箱

python - 属性错误: 'str' object has no attribute 'inWaiting'