我想matplotlib在下面的图中添加一个箭头到一个线图(用图画绘制pgfplots).
我该怎么办(理想情况下箭头的位置和方向应该是参数)?
这是一些实验代码.
from matplotlib import pyplot
import numpy as np
t = np.linspace(-2, 2, 100)
plt.plot(t, np.sin(t))
plt.show()
Run Code Online (Sandbox Code Playgroud)
谢谢.
感谢Jake Vanderplas,我知道如何开始编写动画情节matplotlib.这是一个示例代码:
from matplotlib import pyplot as plt
from matplotlib import animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(0, 100))
line, = plt.plot([], [])
def init():
line.set_data([], [])
return line,
def animate(i):
line.set_data([0, 2], [0,i])
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=20, blit=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)
假设现在我想在循环的帮助下绘制大量函数(比如说四个).我做了一些伏都教程序,试图理解如何模仿下面的逗号,这就是我得到的(不用说它不起作用:) AttributeError: 'tuple' object has no attribute 'axes'.
from matplotlib import pyplot as plt
from matplotlib import animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(0, 100))
line = …Run Code Online (Sandbox Code Playgroud) 我想将其打印为灰度图像。我可以使用以下方法进行转换scikit-image:
from skimage.io import imread
from matplotlib import pyplot as plt
from skimage.color import rgb2gray
img = imread('image.jpg')
plt.grid(which = 'both')
plt.imshow(rgb2gray(img), cmap=plt.cm.gray)
Run Code Online (Sandbox Code Playgroud)
我得到:
这显然不是我想要的。
我的问题是:有没有办法使用scikit-image或使用原始图像numpy和/或mathplotlib数字化图像,以便我得到一个 3D 数组(第一维:X 索引,第二维:Y 索引,第三维:根据颜色图的值)。然后我可以轻松地将颜色图更改为在灰度打印时结果更好的东西?
在我最近的一个问题中,我引用了Jake Vanderplas的一些代码.可以找到以下代码:
from matplotlib import pyplot as plt
from matplotlib import animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(0, 100))
line, = plt.plot([], [])
def init():
line.set_data([], [])
return line,
def animate(i):
line.set_data([0, 2], [0,i])
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=20, blit=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)
在initor animate函数中,返回"value"是line,(用逗号).
问题:返回"值"是否会有line(whitout逗号)?
谢谢