Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

python - How to display only a figure with interactive ipywidgets in RISE slide without associated code

I'm trying to display a figure, with interactive ipywidgets below it, in a RISE slide. The code I'm using to create the figure fills the screen when displayed as a slide and makes it difficult to display the figure and widgets.

I've included a shorter interaction function in the minimum working example below. Currently, to display the graph, everything in Cell 2 is also displayed in the RISE slide.

I've considered including a right scroll bar to scroll past the code (https://rise.readthedocs.io/en/maint-5.5/customize.html#enable-a-right-scroll-bar), or simply adjusting the size of the slide, but I'd prefer to display only the figure and widgets to make it more user-friendly.

Is there a method of creating a figure and associated function in one cell which can be set to 'Skip' in RISE, and displaying the figure in a subsequent cell which can be set to 'Slide'?

This is my first time using RISE, so I may have missed something obvious!

## Cell 1: Slide Type set as 'Skip'

%matplotlib nbagg

import matplotlib.pyplot as plt
import numpy as np
from ipywidgets import interact, IntSlider

## Cell 2: Slide Type set as "Slide"

fig = plt.figure()
ax = fig.add_subplot(111)

def update(seed=0):
    ax.cla()   # Possibly not best practice, but in my real code I have multiple data sources 
               # that interact with the widget variables in different ways and this has 
               # proved the easiest way so far

    np.random.seed(seed)
    x = 10*np.random.rand(10)
    y = np.sin(x)
    ax.plot(x, y, "o")
    
interact(update, seed=IntSlider(min=0, max=10, step=1))
question from:https://stackoverflow.com/questions/65851196/how-to-display-only-a-figure-with-interactive-ipywidgets-in-rise-slide-without-a

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...