ABr*_*eit 3 plot matplotlib python-2.7
这是我第一次发帖!
我正在使用Calalap绘制漂亮的日历图来分析一些数据。日历图正在使用颜色图显示天之间的对比。我的问题是,calap不能提供友好的工具来显示与日历图关联的色条。我想知道你们中的一个是否对此有解决方案。理想的情况是为整个图形而不只是一个轴设置颜色条。
Calentap的文档:http ://pythonhosted.org/calmap/
import pandas as pd
import numpy as np
import calmap # pip install calmap
%matplotlib inline
df=pd.DataFrame(data=np.random.randn(500,1)
,index=pd.date_range(start='2014-01-01 00:00:00',freq='1D',periods =500)
,columns=['data'])
fig,ax=calmap.calendarplot(df['data'],
fillcolor='grey', linewidth=0,cmap='RdYlGn',
fig_kws=dict(figsize=(17,8)))
fig.suptitle('Calendar view' ,fontsize=20,y=1.08)
Run Code Online (Sandbox Code Playgroud)
镇静图示例
在martijnvermaat / calmap上挖掘镇定代码,我知道
ax.pcolormesh
具有背景的对象,然后再创建具有实际数据的对象,再加上其他东西。要深入研究与轴相关的对象,您可以使用(我假设您在此处进行任何操作之前都已导入了代码并进行了数据初始化):
ax[0].get_children()
[<matplotlib.collections.QuadMesh at 0x11ebd9e10>,
<matplotlib.collections.QuadMesh at 0x11ebe9210>, <- that's the one we need!
<matplotlib.spines.Spine at 0x11e85a910>,
<matplotlib.spines.Spine at 0x11e865250>,
<matplotlib.spines.Spine at 0x11e85ad10>,
<matplotlib.spines.Spine at 0x11e865490>,
<matplotlib.axis.XAxis at 0x11e85a810>,
<matplotlib.axis.YAxis at 0x11e74ba90>,
<matplotlib.text.Text at 0x11e951dd0>,
<matplotlib.text.Text at 0x11e951e50>,
<matplotlib.text.Text at 0x11e951ed0>,
<matplotlib.patches.Rectangle at 0x11e951f10>]
Run Code Online (Sandbox Code Playgroud)
现在,我们可以按照此答案中的建议使用fig.colorbar
(plt.colorbar
是该函数的包装器)
Matplotlib 2 Subplots,1 Colorbar:
fig,ax=calmap.calendarplot(df['data'],
fillcolor='grey', linewidth=0,cmap='RdYlGn',
fig_kws=dict(figsize=(17,8)))
fig.colorbar(ax[0].get_children()[1], ax=ax.ravel().tolist())
Run Code Online (Sandbox Code Playgroud)
这会在第一个绘图中生成仅引用颜色的垂直colobar,但是所有绘图的颜色都相同。
我仍在使用轴和水平轴更好的位置,但是从这里开始应该很容易。
作为奖励,用于单个年度图:
fig = plt.figure(figsize=(20,8))
ax = fig.add_subplot(111)
cax = calmap.yearplot(df, year=2014, ax=ax, cmap='YlGn')
fig.colorbar(cax.get_children()[1], ax=cax, orientation='horizontal')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1138 次 |
最近记录: |