Используя виджет %matplotlib в блокноте Jupyer, я получаю красивый интерактивный график. Но все дублируется.
Когда я удаляю ключевое слово display. Он визуализируется, но мне нужен HBox, чтобы выровнять виджеты. В противном случае ничего не было бы выровнено.
%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[testing_radius, :, :].copy()
axs[0].imshow(image, cmap='viridis', aspect='auto') # Display the slice
axs[0].set_title(f'{body.centers_scaled[title]}') # 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[18])
max = np.max(data[18])
mean = np.mean(data[18])
std = np.std(data[18])
threshold= max - std*val
image = data[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)
Подробнее здесь: https://stackoverflow.com/questions/793 ... plot-comin
Используя виджет %matplotlib в блокноте Jupyter, я получаю красивый интерактивный график. Но все дублируется ⇐ Python
Программы на Python
1771761478
Anonymous
Используя виджет %matplotlib в блокноте Jupyer, я получаю красивый интерактивный график. Но все дублируется.
Когда я удаляю ключевое слово display. Он визуализируется, но мне нужен HBox, чтобы выровнять виджеты. В противном случае ничего не было бы выровнено.
%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)
Подробнее здесь: [url]https://stackoverflow.com/questions/79343557/using-matplotlib-widget-in-jupyer-notebook-and-i-get-the-interactive-plot-comin[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия