我写了下面的代码来可视化一个游戏情节。当尝试使用axes.set_xticks
更改x轴标签时,我得到AttributeError: 'list' object has no attribute 'set_xticks'
import joypy
import pandas as pd
from matplotlib import pyplot as plt
data = pd.DataFrame.from_records([['twitter', 1],
['twitter', 6],
['wikipedia', 1],
['wikipedia', 3],
['indymedia', 1],
['indymedia', 9]], columns=['platform','day'])
# Get number of days in the dataset
numdays = max(set(data['day'].tolist()))
# Generate date strings from a manually set start date
start_date = "2010-01-01"
dates = pd.date_range(start_date, periods=numdays)
dates = [str(date)[:-9] for date in dates]
fig, axes = joypy.joyplot(data,by="platform")
axes.set_xticks(range(numdays)); axes.set_xticklabels(dates)
plt.show()
预期的输出应该如下所示,但是日期从dates
作为tickLabel。在
要使用python matplotlib绘制日期图,您应该使用plot_date函数。
图,ax=plt.子批次()
ax.plot_日期(日期,数据1,'-')
我把完整的例子放在pastebin中,点击链接: https://pastebin.com/sVPUZaeM
Python版本测试成功:2.7.12
此代码生成:this follow plot
由于}应该是轴的列表,所以您可能需要为最后一个轴设置标签
joypy.joyplot(..)
返回一个figure
的元组,axes
和{相关问题 更多 >
编程相关推荐