Wenn ich das %matplotlib-Widget im Jupyter-Notebook verwende, bekomme ich die interaktive Handlung gut heraus. Aber allePython

Python-Programme
Guest
 Wenn ich das %matplotlib-Widget im Jupyter-Notebook verwende, bekomme ich die interaktive Handlung gut heraus. Aber alle

Post by Guest »

Wenn ich das %matplotlib-Widget im Jupyer-Notebook verwende, bekomme ich die interaktive Handlung gut heraus. Aber alles ist dupliziert.
Wenn ich das Display-Keyword entferne. Es wird gerendert, aber ich benötige die HBox, um die Widgets auszurichten. Wenn nicht, würde nichts ausgerichtet werden.

Code: Select all

%matplotlib widget
import tomolyzer as t
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact, IntSlider, FloatSlider, Dropdown, VBox, HBox, Layout
from IPython.display import display  # Import display for rendering widgets
import logging
from scipy.fft import fft2, fftshift
import scipy.ndimage as S
import os
from tqdm import tqdm
fig, axs = plt.subplots(1, 2, figsize=(10, 5))  # 1 row and 3 columns figure size of 15 inches wide and 5 inches tall.

axs[0].axis("off")
axs[1].axis("off")

std = 0
max = 0
factor = max - std*2
i=0
image = data[i][testing_radius, :, :].copy()
axs[0].imshow(image, cmap='viridis', aspect='auto')  # Display the slice
axs[0].set_title(f'{body.centers_scaled[title][i]}')  # Title for the slice
axs[0].set_xlabel(f'{np.mean(image):.2e}')
axs[0].set_ylabel('YX')
axs[0].set_xticks([0,mid_x/2,mid_x])
axs[0].set_yticks([0,mid_y/2,mid_y])

axs[1].imshow(image, cmap='viridis', aspect='auto')  # Display the slice

def updatePlot(val):
min = np.min(data[i][18])
max = np.max(data[i][18])
mean = np.mean(data[i][18])
std = np.std(data[i][18])
threshold= max - std*val
image = data[i][testing_radius, :, :].copy()
# positve intercept
image[np.where(image > max - std*val)] = 0
image[np.where(image < max - std*val)] = 1
axs[1].clear()  # Clear previous plot
axs[1].imshow(image, cmap='viridis', aspect='auto')  # Display the slice
axs[1].text(
0.5, -0.1, f"{threshold:.2e}",
transform=axs[1].transAxes, ha='center', va='top', fontsize=12
)

std_slider = FloatSlider(min=0,max=7,step=0.001,value=0,description='Std',orientation='vertical', layout=Layout(height='300px'))
x=interact(updatePlot,val = std_slider)

plots_and_slider = HBox([std_slider,fig.canvas], layout=Layout(align_items='center'))

display(plots_and_slider)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post