如何使用带有颜色条的 calmmap 在斧头上绘制热图?
How to draw a heatmap using calmap with the colorbar on the ax?
我有一个 pandas df 如下:
ipdb> df_calmap
count
start_datetime
2021-03-10 17:40:24 1
2021-03-11 23:41:34 1
2021-03-12 00:41:42 1
2021-03-12 13:11:25 1
2021-03-15 00:02:49 1
2021-03-15 11:40:50 1
2021-03-17 12:42:14 1
2021-03-18 01:50:22 1
2021-03-21 19:10:55 1
2021-03-22 15:00:06 1
2021-03-25 00:22:22 1
2021-03-26 16:33:11 1
2021-03-29 19:16:59 1
2021-03-30 17:58:53 1
2021-03-31 17:46:08 1
我可以使用 calmap 绘制热图,但是我希望颜色条与显示的图像大小相同 在对我的问题的类似回答中。但是,代码对我不起作用。我好像达不到我想要的。
我已经搜索了 matplotlib 文档,但我也无法使其工作。这是我当前的代码。非常感谢。
def plot_trades_heatmap_chart(self):
df_calmap = ...
fig, ax = calmap.calendarplot(df_calmap['count'], monthticks=1, daylabels='MTWTFSS',
dayticks=[0, 1, 2, 3, 4, 5, 6], cmap='RdYlGn',
fillcolor='whitesmoke', linewidth=0.3,
fig_kws=dict(figsize=(8, 4)))
# Vertical
fig.colorbar(ax[0].get_children()[1], ax=ax.ravel().tolist())
plt.xlabel("Trades grouped by day", fontsize=12)
fig.suptitle('Number of trades per day heatmap', fontsize=16)
return(fig)
预期的输出应该是这样的:
非常感谢!
这里有一个,不过是一年剧情。我试着看看我是否可以用你想要的日历图做同样的事情,但没有成功。所以我在年图上做了一些改动,把代码写成日历图的样式。
df_calmap.set_index('start_datetime', inplace=True)
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
yyyy = 2021
fig = plt.figure(figsize=(20,4))
ax = fig.add_subplot(111)
cax = calmap.yearplot(df_calmap['count'], year=yyyy)
plt.xlabel("Trades grouped by day", fontsize=12)
plt.ylabel(yyyy, fontsize=58, color='#f5f5f5', weight='bold')
fig.suptitle('Number of trades per day heatmap', fontsize=16)
divider = make_axes_locatable(cax)
lcax = divider.append_axes("right", size="2%", pad=0.5)
fig.colorbar(cax.get_children()[1], cax=lcax)
我有一个 pandas df 如下:
ipdb> df_calmap
count
start_datetime
2021-03-10 17:40:24 1
2021-03-11 23:41:34 1
2021-03-12 00:41:42 1
2021-03-12 13:11:25 1
2021-03-15 00:02:49 1
2021-03-15 11:40:50 1
2021-03-17 12:42:14 1
2021-03-18 01:50:22 1
2021-03-21 19:10:55 1
2021-03-22 15:00:06 1
2021-03-25 00:22:22 1
2021-03-26 16:33:11 1
2021-03-29 19:16:59 1
2021-03-30 17:58:53 1
2021-03-31 17:46:08 1
我可以使用 calmap 绘制热图,但是我希望颜色条与显示的图像大小相同
我已经搜索了 matplotlib 文档,但我也无法使其工作。这是我当前的代码。非常感谢。
def plot_trades_heatmap_chart(self):
df_calmap = ...
fig, ax = calmap.calendarplot(df_calmap['count'], monthticks=1, daylabels='MTWTFSS',
dayticks=[0, 1, 2, 3, 4, 5, 6], cmap='RdYlGn',
fillcolor='whitesmoke', linewidth=0.3,
fig_kws=dict(figsize=(8, 4)))
# Vertical
fig.colorbar(ax[0].get_children()[1], ax=ax.ravel().tolist())
plt.xlabel("Trades grouped by day", fontsize=12)
fig.suptitle('Number of trades per day heatmap', fontsize=16)
return(fig)
预期的输出应该是这样的:
非常感谢!
这里有一个
df_calmap.set_index('start_datetime', inplace=True)
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
yyyy = 2021
fig = plt.figure(figsize=(20,4))
ax = fig.add_subplot(111)
cax = calmap.yearplot(df_calmap['count'], year=yyyy)
plt.xlabel("Trades grouped by day", fontsize=12)
plt.ylabel(yyyy, fontsize=58, color='#f5f5f5', weight='bold')
fig.suptitle('Number of trades per day heatmap', fontsize=16)
divider = make_axes_locatable(cax)
lcax = divider.append_axes("right", size="2%", pad=0.5)
fig.colorbar(cax.get_children()[1], cax=lcax)