Issue
The following code yields a graph.
import numpy as np, pandas as pd
import matplotlib.pyplot as plt
import plotly, plotly.express as px
arr = np.array(np.arange(stop=257, start=1).reshape(-1,4,4))
dfs = [pd.DataFrame(i, index=["row1", "row2", "row3", "row4"], columns=["col1", "col2", "col3", "col4"])for i in arr]
plt.plot(dfs[1])
plt.show()
but the following does not
import numpy as np, pandas as pd
import matplotlib.pyplot as plt
import plotly, plotly.express as px
arr = np.array(np.arange(stop=257, start=1).reshape(-1,4,4))
dfs = [pd.DataFrame(i, index=["row1", "row2", "row3", "row4"], columns=["col1", "col2", "col3", "col4"])for i in arr]
px.line(dfs[1],x=dfs[1].index, y="col1").show()
clarification: both codes show plots when run in terminal but I can only see plot from matplotlib when these codes are run in spyder (there spyder tab "plots" only contains plot from matplotlib).
Solution
That's because in your second code, you're calling plotly.express.line
to make a plotly plot (which is interactive) and I don't think Spyder can handle that.
Plotly's Python graphing library makes interactive, publication-quality graphs.
You have at least, three choices/workarounds:
Either (1) use Jupyter Notebook or Jupyterlab.
Or (2) in Spyder, make the plot static (as well as your matplotlib plot) by adding these two lines :
import plotly.io as pio
pio.renderers.default='svg'
Or (3), always in Spyder, set your default Internet browser as the renderer :
import plotly.io as pio
pio.renderers.default='browser'
Answered By - Timeless
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.