plotly / plotly.rs

Plotly for Rust

Home Page:https://docs.rs/plotly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

import error for `.mode(Mode::Markers)` for Scatter plot

whatthedev-eth opened this issue · comments

Starting with code here, in Jupyter Notebook, everything works fine:
https://github.com/igiagkiozis/plotly/blob/master/examples/jupyter/jupyter_notebook.ipynb

Then change
let trace = Scatter::new(x0, y0);
to
let trace = Scatter::new(x0, y0).mode(Mode::Markers);
to use syntax shown in example here
https://igiagkiozis.github.io/plotly/content/recipes/basic_charts/scatter_plots.html#simple-scatter-plot
but error is caused: Error: consider importing this trait

In importing Mode, all its traits should be imported, correct? Or is there another way to import the traits of Mode?

Note, if Markers is changed to lower case markers, then the error also includes

[E0599] Error: no variant or associated item named `markers` found for enum `Mode` in the current scope

   ╭─[command_23:1:1]
   │
 4 │ let trace = Scatter::new(x0, y0).mode(Mode::markers);
   ·                                             ───┬───  
   ·                                                ╰───── variant or associated item not found in `Mode`
   ·                                                │     
   ·                                                ╰───── help: there is a variant with a similar name: `Markers`
───╯

JupyterLab v3.5.2, extensions are:
jupyterlab-plotly v5.9.0
@jupyter-widgets/jupyterlab-manager v3.0.0
@pyviz/jupyterlab_pyviz v2.0.2

enabled nbextension:
jupyterlab-plotly/extension
jupyter-js-widgets/extension

Thanks!

What an unhelpful error message! The trait it is asking for is plotly::Trace.

Change the line in your imports from

use plotly::{Plot, Scatter};

to

use plotly::{Plot, Scatter, Trace};

and that should be working.

Works perfectly now. Thank you!