Plotly: How to retrieve values for major ticks and gridlines?(Plotly:如何检索主要刻度线和网格线的值?)
问题描述
我想检索该图中突出显示的 x 值:
I'd like to retrieve the x-values highlighted in this plot:
绘图是使用此代码段在 Jupyter Notebook 中生成的:
The plot is generated in a Jupyter Notebook using this snippet:
import plotly
import cufflinks as cf
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import pandas as pd
import numpy as np
# setup
init_notebook_mode(connected=True)
np.random.seed(123)
cf.set_config_file(theme='pearl')
# Random data using cufflinks
df = cf.datagen.lines()
# plot
fig = df.iplot(asFigure=True, kind='scatter',xTitle='Dates',yTitle='Returns',title='Returns')
iplot(fig)
<小时>
这是我尝试过的:
使用此设置,您只需在笔记本中运行 fig 即可检索每个系列的每个 x 和 y 值.但刻度值无处可寻.
With this setup, you can retrieve every x and y value for every series by simply running fig in the notebook. But the tick values are nowhere to be found.
我也尝试过深入研究 dir(fig),并认为 fig.axis 的输出可能会解决问题,但没有:
I'v also tried digging deeper in dir(fig), and thought maybe the output from fig.axis would do the trick, but no:
{'x1': {'gridcolor': '#E1E5ED',
'showgrid': True,
'tickfont': {'color': '#4D5663'},
'title': {'text': 'Dates', 'font': {'color': '#4D5663'}},
'zerolinecolor': '#E1E5ED'},
'y1': {'gridcolor': '#E1E5ED',
'showgrid': True,
'tickfont': {'color': '#4D5663'},
'title': {'text': 'Returns', 'font': {'color': '#4D5663'}},
'zerolinecolor': '#E1E5ED'}}
然而,网格和刻度还有其他选项,例如 'showgrid': True 和 'tickfont',但这些值似乎在某处隐藏"否则.
There are however other options for the grid and ticks there like 'showgrid': True, and 'tickfont', but the values seem to be "hidden" somewhere else.
有什么建议吗?
推荐答案
此数据仅在 Javascript 上下文中可用,因此很遗憾无法从 Python 访问.
This data is only available in the Javascript context, and so unfortunately is inaccessible from Python.
这篇关于Plotly:如何检索主要刻度线和网格线的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Plotly:如何检索主要刻度线和网格线的值?
基础教程推荐
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
