`mpl_to_plotly` does not preserve axis labels (bar plots are useless)
未关闭
还没有人认领这个 Issue。
bug
P3
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
While mpl_to_plotly is little known and receives little love, this bug is pretty easy to fix. Would you be open to a PR?
import matplotlib.pyplot as plt
from plotly.tools import mpl_to_plotly
from plotly.offline import plot
In matplotlib this produces a barplot with labels:
labels = ['a', 'b', 'c']
values = [1, 2, 3]
f = plt.figure(figsize=(6, 4))
plt.bar(labels, values)
plt.tight_layout()
But conversion to plotly looses the labels:
plotly_fig = mpl_to_plotly(f)
plot(plotly_fig)
A minimal fix would be to modify prep_ticks by appending:
if axis_dict.get("type") == "date":
return axis_dict
vals = []
texts = []
for tick in axis.majorTicks:
vals.append(tick.get_loc())
texts.append(tick.label1.get_text())
if texts:
axis_dict = {}
axis_dict['tickmode'] = 'array'
axis_dict['tickvals'] = vals
axis_dict['ticktext'] = texts
return axis_dict
which produces:
prep_ticks is defined in:
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 plotly/matplotlylib/mpltools.py 中的 prep_ticks 开始,然后重现提供的 matplotlib 柱状图和 mpl_to_plotly 转换。保留转换后 Plotly 图形中的原始坐标轴标签,并验证生成的图表与演示的带标签输出一致,同时不影响日期轴处理。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 48/100