[英]Plotly: How to offset the grid on a heatmap?
As you can see from the screenshot, the gridlines start directly in the middle of the boxes.从屏幕截图中可以看出,网格线直接从框的中间开始。
Is there any way I can do that with plotly?有什么办法可以用 plotly 做到这一点?
Here is the setup for the heatmap:这是热图的设置:
colorscale= [[0, 'yellow'], [0.7, 'red'], [1, 'darkred']]
trace_activity = go.Heatmap(
z=activity_orgname['activity'],
x=activity_orgname['month'],
y=activity_orgname['org_name'].astype(str),
hoverongaps = False,colorscale=colorscale)
layout = go.Layout(title='Activity "' + ac_name + '" per Month:',
xaxis={'type':'category', "gridcolor": "rgba(157, 166, 0, 1)"},
yaxis={'type':'category', "gridcolor": "rgba(157, 166, 0, 1)"},
plot_bgcolor="white")
fig = go.Figure(data=[trace_activity],
layout=layout,
)
iplot(fig)
This is what you're looking for:这就是你要找的:
fig.update_xaxes(tickson='boundaries')
The other option is:另一种选择是:
fig.update_xaxes(tickson='labels')
Complete code:完整代码:
import plotly.graph_objects as go
fig = go.Figure(data=go.Heatmap(
z=[[1, None, None, 50, 1], [20, None, None, 80, 30], [30, 60, None, None, 20]],
x=['01.01.2020', '01.02.2020', '01.03.2020', '01.04.2020', '01.05.2020'],
y=['Morning', 'Afternoon', 'Evening'],
hoverongaps = False))
fig.update_xaxes(gridcolor='steelblue',
ticks="outside",
tickson="boundaries",
ticklen=20
)
fig.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.