我正在尝试弄清楚如何使用袖扣控制以绘图方式生成的图形的布局。例如:此代码将生成一个图形,其中 yaxis 标签位于左侧。如何将 Y 轴标签移动到图表的另一侧?
import pandas as pd
import cufflinks as cf
cf.go_offline()
from plotly.offline import download_plotlyjs, plot,iplot
df.iplot(kind='scatter',mode='lines+markers',x='Time',title='Events over Time',
y='Events',margin={'l':450})
我在网上搜索了一段时间,所以我在这里:)。
Plotly API 在这里:https://plot.ly/python/reference/#layout-yaxis-side
虽然我无法弄清楚如何应用这个:
侧面(枚举:“顶部”|“底部”|“左”|“右”)
确定 x (y) 轴是位于绘图区域的“底部”(“左”)还是“顶部”(“右”)。
请您参考如下方法:
您可以使用 iplot 方法的 asFigure=True 属性返回整个图形。获得图形后,您可以相应地更新底层绘图布局。
_data = df.iplot(kind='scatter', mode='lines+markers',
x='Time', y='Events',
title='Events over Time', asFigure=True)
_data['layout']['yaxis'] = dict(side='left')
_data.iplot()
