Enabling 3D plots?
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 28/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- matplotlib, python
调研方向
从 plotnine/ggplot.py 开始,重点查看 _build、_create_figure 和 _create_subplots,然后检查 plotnine/facets/layout.py 和 geom_point.draw_groups()。将提议的扩展点与现有的分面和坐标处理进行比较。完成的要求是:达成一个支持 3D 图和分面的实现方案;如果原生 3D 支持不在范围内,则需要有明确的可扩展路径。
由索引模型根据 Issue 内容生成。
描述
Could 3D plots be supported by plotnine, or if not, could the internals be slightly adjusted to enable easy extension to 3D plots? Currently with a simple hack it is possible to get a simple 3d plotnine plot:
from plotnine import scale_color_manual, scale_shape_manual, theme_minimal
from plotnine.data import mtcars
mtcars['transmission'] = mtcars['am'].replace({0: 'automatic', 1: 'manual'})
(
ggplot_3d(mtcars)
+ aes(x='hp', y='disp', z='mpg', shape='transmission', color='transmission')
+ geom_point_3d()
+ theme_minimal()
+ scale_shape_manual(values={'automatic': 'o', 'manual': '*'})
+ scale_color_manual(values={'automatic': 'red', 'manual': 'blue'})
)

The hack is:
from plotnine import ggplot, geom_point
from plotnine.utils import to_rgba, SIZE_FACTOR
class ggplot_3d(ggplot):
def _create_figure(self):
figure = plt.figure()
axs = [plt.axes(projection='3d')]
figure._themeable = {}
self.figure = figure
self.axs = axs
return figure, axs
def _draw_labels(self):
ax = self.axs[0]
ax.set_xlabel(self.layout.xlabel(self.labels))
ax.set_ylabel(self.layout.ylabel(self.labels))
ax.set_zlabel(self.labels['z'])
class geom_point_3d(geom_point):
REQUIRED_AES = {'x', 'y', 'z'}
@staticmethod
def draw_unit(data, panel_params, coord, ax, **params):
size = ((data['size']+data['stroke'])**2)*np.pi
stroke = data['stroke'] * SIZE_FACTOR
color = to_rgba(data['color'], data['alpha'])
if all(c is None for c in data['fill']):
fill = color
else:
fill = to_rgba(data['fill'], data['alpha'])
ax.scatter3D(
data['x'],
data['y'],
data['z'],
s=size,
facecolor=fill,
edgecolor=color,
marker=data.loc[0, 'shape'],
)
@staticmethod
def draw_group(data, panel_params, coord, ax, **params):
data = coord.transform(data, panel_params)
units = 'shape'
for _, udata in data.groupby(units, dropna=False):
udata.reset_index(inplace=True, drop=True)
geom_point_3d.draw_unit(udata, panel_params, coord, ax, **params)
However, because it is bypassing self.facet.make_axes() call in _create_figure() it does not support faceting.
While I would prefer plotnine to just support 3D plots, I fully respect if this is not aligned with the vision of the project; in that case the following places could be reworked to simplify extending:
- to allow extending
geom_pointeasier, thegeom_point.draw_groups()method could be a classmethod rather than a static method, and instead of using hard-codedgeom_pointit would usecls; presumably this would be also need for other geoms which can have 3d equivalents (line, area, etc). - to allow to add zlabel special handling in addition to
xlabelandylabela new common methodLayout.label(self, labels, axis)could replaceLayout.xlabel(self, labels)andLayout.ylabel(self, labels)OR the hard-coded use ofself.layout = Layout()inggplot._buildcould be replaced with either a new methodggplot._init_layout()or a new class attributelayout_class = Layoutcould be added (and then the call would be replaced withself.layout = self.layout_class()); - to allow for faceting support, the
fig.add_subplot(gs[i - 1])call in_create_subplotsshould allow to passprojection='3d'keyword argument; this could be conditional on layout having a projection attribute.
Of course there some more changes for full integration (e.g. fliping of coordinates would need to know around which axis), but I believe that very little changes would be needed to gain quite a lot in terms of usability.
- 主要语言
- Python
- 星标
- 4.8k
- 派生
- 260
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 4
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
has2k1/plotnine 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
Enhancement
难度 3/5 半天 新手友好度 55/100
has2k1/plotnine#1141 · 2 条评论 ·
维护者通常 1 天内回复
-
Enhancement
难度 4/5 3-5 天 新手友好度 52/100
has2k1/plotnine#1081 · 3 条评论 ·
维护者通常 1 天内回复
-
Discussion
难度 5/5 一周以上 新手友好度 30/100
has2k1/plotnine#1047 · 15 条评论 · 3 个 reaction ·
维护者通常 1 天内回复
-
Documentation Plot Composition Question
难度 3/5 1-2 天 新手友好度 45/100
has2k1/plotnine#1036 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
Significant-Gravitas/AutoGPT#16733 ·
维护者通常 1 天内回复
-
changelog investigate
难度 1/5 1 小时以内 新手友好度 74/100
ramnes/notion-sdk-py#444 ·
-
documentation
难度 2/5 1-3 小时 新手友好度 69/100
Judgment-Pack/judgment-pack-spec#299 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
QuantConnect/Documentation#2858 ·
维护者通常 1 天内回复
-
good first issue
难度 2/5 1-3 小时 新手友好度 90/100
btclib-org/btclib#3047 ·
维护者通常 1 天内回复