I'm creating a plotly chart in jupyter notebook. Because I'm testing some algorithm I want to add data after the initial fig2.show(). But when I update the data and call fig2.show again a new chart is being rendered. How can I update the chart instead of creating a new chart?
This should be an easy task - but it's way to hard to find for me in the documentation.
import plotly.offline as pyo
import plotly.graph_objs as go
import numpy as np
# Set notebook mode to work in offline
pyo.init_notebook_mode()
fig2 = go.Figure(data=go.Scatter(x=moreX2, y=moreY2))
fig2.show()
Then I'm using update:
moreX2.append(2)
moreY2.append(5)
fig2.data[0].update({"x": moreX2, "y": moreY2})
The chart isn't being rerendered and I tried to call fig.show() again, which just creates a new chart.
This answer worked for me, and seems like the ideal answer to this question as well. I've voted to mark this as a duplicate.
To summarize: by wrapping the Figure in a FigureWidget, we can now do exactly what the OP wanted. Although on Colab I did have to give some extra permission by calling the following:
from google.colab import output
output.enable_custom_widget_manager()
Related
I understand that it is possible to export a Plotly graph, and that I can display it.
While sharing notebooks, the matplotlib plots remain intact in the Jupyter Notebooks, however, the Plotly graphs do not. They simply disappear
I understand that the Plotly graph is browser rendered, but is there any way I can store the graph in the ipynb file when I export it?
Is there any way that I can display the Plotly graph, just like the matplotlib graph?
Edit: As suggested in an answer, I tried to save it to a figure object, and display that, but no luck there either :/
If you put the code for a series of graphs in a single cell, execute it and save it, I think it will be displayed the next time you open it.
import plotly.express as px
df = px.data.iris() # iris is a pandas DataFrame
fig = px.scatter(df, x="sepal_width", y="sepal_length")
fig.show()
I've been trying to change the tick label of my axis. I've imported them from a csv, and have changed the label, but I can't change the tick. I'm just starting out, so if I have any of the terms wrong just let me know. My code is outlined below.
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv ('countries.csv')
uk = data[data.ISO_3_CODE == "GBR"]
plt.plot(uk.date_epicrv)
plt.plot(uk.CumCase)
plt.xlabel('Time')
plt.ylabel("Cumulative infection rate")
plt.show
The csv can be found at https://data.humdata.org/dataset/coronavirus-covid-19-cases-and-deaths if you need it. Sorry I couldn't be more specific, trying to learn a new skill and I believe I'm using the wrong terms to search.
Well, I feel like a fool. I was formatting my graph wrong.
Where I had
plt.plot(uk.date_epicrv)
plt.plot(uk.CumCase)
I should have used
plt.plot(uk.date_epicrv, uk.CumCase)
I was trying to plot both graphs on the x-axis. Closing the question now, hope this helps anyone with the issue down the line.
Trying to build seaborn FacetGrid plots in a Jupyter notebook. Upon creation, it displays just fine. But if I manipulate the chart and want to see it again, I cannot. I can only get the object listing.
How can I show the chart a second time?
You need to state the figure in a new cell to let it be displayed with the inline backend.
g.fig
g.fig doesn't work.Instead, g.figure works out.
I am trying to produce a simple histogram of categorical data with the following code
import pandas as pd
from bokeh.plotting import figure, show
# some fake categories and count data
counts = pd.Series({'Cat0':1599, 'Cat1':1357, 'Cat2':671,
'Cat3':610, 'Cat4':446, 'Cat5':210})
# pull out the categories from the index
cats = list(counts.keys())
plt = figure(x_range=cats)
plt.vbar(cats, top=list(counts.values), width=2, line_color='green')
show(plt)
but instead of a plot I get
Javascript error adding output!
Error: Error rendering Bokeh model: could not find tag with id: e7346df5-7d3d-4f34-92e2-9e59eb36ec41
See your browser Javascript console for more details.
Is this a bug or have I specified something wrong?
I am using Firefox 54.0 running on Ubuntu (kernel 4.10.0). Other Bokeh plots run without a problem. I am outputting them inline to a Jupyter notebook.
Bokeh is bokeh-0.12.4-py3.6.
Not sure what is causing the problem, but re-executing
from bokeh.plotting import figure, show, output_notebook
and re-running
output_notebook()
solves the problem and plots again show in the notebook.
I am creating a bar chart with seaborn, and it's not generating any sort of error, but nothing happens either.
This is the code I have:
import pandas
import numpy
import matplotlib.pyplot as plt
import seaborn
data = pandas.read_csv('fy15crime.csv', low_memory = False)
seaborn.countplot(x="primary_type", data=data)
plt.xlabel('crime')
plt.ylabel('amount')
seaborn.plt.show()
I added "seaborn.plt.show() in an effort to have it show up, but it isn't working still.
You should place this line somewhere in the top cell in Jupyter to enable inline plotting:
%matplotlib inline
It's simply plt.show() you were close. No need for seaborn
I was using PyCharm using a standard Python file and I had the best luck with the following:
Move code to a Jupyter notebook (which can you do inside of PyCharm by right clicking on the project and choosing new - Jupyter Notebook)
If running a chart that takes a lot of processing time it might not have been obvious before, but in Jupyter mode you can easily see when the cell has finished processing.