Enabling 3D plots?
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 28/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- matplotlib, python
- Área
- data-visualization
Línea de trabajo
Comienza con plotnine/ggplot.py, especialmente _build, _create_figure y _create_subplots, y después inspecciona plotnine/facets/layout.py y geom_point.draw_groups(). Compara los puntos de extensión propuestos con la gestión existente de facetas y coordenadas. Se considerará terminado cuando haya una implementación acordada que admita gráficos 3D y facetas, o un camino claro de extensibilidad si la compatibilidad nativa con 3D queda fuera del alcance.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 4.8k
- Forks
- 260
- Merge medio
- 2 d 12 h
- PR fusionados (30 d)
- 4
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de has2k1/plotnine
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
Enhancement
Dificultad 3/5 Medio día Aptitud para principiantes 55/100
has2k1/plotnine#1141 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
has2k1/plotnine#1081 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Discussion
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
has2k1/plotnine#1047 · 15 comentarios · 3 reacciones ·
Los mantenedores suelen responder en 1 día
-
Documentation Plot Composition Question
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
has2k1/plotnine#1036 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de has2k1/plotnine
Issues similares
-
`destroy` sans terminal répond « Aborted. » au lieu de réclamer `--yes` comme `clean` et `reset`Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
stephrobert/dsoxlab#354 ·
Los mantenedores suelen responder en 1 día
-
hardware help wanted testing
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
jasonacox/pypowerwall#472 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: DoubleMLRDDData accepts a score_col that is no data column (as in its docstring example); the running variable then becomes a covariate and RDFlex failsPosiblemente ocupada @vrjdev la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
DoubleML/doubleml-for-py#455 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: Python mod.Box[T] annotation gets a false generic_arg edge that replaces the parameter_type one ('is' on tree-sitter nodes)Posiblemente ocupada @rohit-jsfreaky la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Graphify-Labs/graphify#5110 · 1 comentario ·
Los mantenedores suelen responder en 2 días