我遇到的问题是,在 jupyter 笔记本中显示 JavaScript 动画也会显示该图:
示例代码:
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
def init():
line.set_data([], [])
return line,
def animate(i):
x = np.linspace(0, 2, 1000)
y = np.sin(2 * np.pi * (x - 0.01 * i))
line.set_data(x, y)
return line,
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval=20, blit=True)
HTML(anim.to_jshtml())
Run Code Online (Sandbox Code Playgroud)
请注意,这会产生两个绘图,而不仅仅是动画。
另一方面,我尝试使用以下命令运行它:
HTML(anim.to_html5_video())
Run Code Online (Sandbox Code Playgroud)
但这给了我以下错误之一:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~\AppData\Local\Continuum\miniconda3\lib\site-packages\matplotlib\animation.py in __getitem__(self, name)
169 try:
--> 170 return self.avail[name]
171 …Run Code Online (Sandbox Code Playgroud) 假设我有一个数据表,其中客户购买了这样的东西:
Customer|Price|Quantity Sold
a | 200 | 3.3
b | 120 | 4.1
c | 040 | 12.0
d | 030 | 16.76
Run Code Online (Sandbox Code Playgroud)
这应该是数据表的粗略表示,其中包含同一产品的客户、价格和销售数量。
我想弄清楚如何计算此信息的购买价格中位数。
我对方法有点困惑,因为我知道在 pandas 中获取分位数很容易data[row].quantile(x)
但由于每一行实际上代表多个观察结果,我不确定如何获取分位数。
编辑:最重要的是,主要问题是销售数量不离散。这是一个连续变量。(我们就像谈论米、公斤等,因此不能选择创建更多行。)
这是我的代码:
from matplotlib.ticker import FuncFormatter
import pandas as pd
import numpy as np
from datetime import datetime
from matplotlib import pyplot as plt
dates = pd.date_range('01/01/2016', datetime.today(), freq = 'M')
X = pd.DataFrame(index = dates)
X['values'] = np.random.rand(len(X)) * 300
fig, ax = plt.subplots()
fig.set_size_inches(8 * phi, 8 )
X['values'].plot(ax = ax)
ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '$ {:,.0f}'.format(x)))
plt.show()
Run Code Online (Sandbox Code Playgroud)
我已经尝试了半个小时了,我真的需要一些帮助。
在 x 轴的小刻度标签上显示其他月份的最干净、最简单的方法是什么?只显示以 J 开头的月份,而不是出于某种原因想要执行的操作。...
注意:我确实安装了海运。