Я пытаюсь создать интерактивный график с помощью Plotly, но он продолжает печатать два графика вместо одного.
Вот код, который я использую, и результат, который я получил :
# Initialize the position of the bar with the first start value
start_value_bot = plateaus_bot[0][0] # First start value in plateaus_bot
start_value_top = plateaus_top[0][0] # First start value in plateaus_top
# Calculate the limits for the x and y axes based on the values of X_top and X_bot
x_min = min(fit['tAtm'])
x_max = max(fit['tAtm'])
y_min = min(fit['X_bot'].min(), fit['X_top'].min()) # The minimum value between X_bot and X_top
y_max = max(fit['X_bot'].max(), fit['X_top'].max()) + 100 # The maximum value between X_bot and X_top
# Create the initial figure with FigureWidget
fig = go.FigureWidget()
# Add the X_top and X_bot curves
fig.add_trace(go.Scatter(x=fit['tAtm'], y=fit['X_top'], mode='lines', name='X top'))
fig.add_trace(go.Scatter(x=fit['tAtm'], y=fit['X_bot'], mode='lines', name='X bot'))
# Add the first vertical line initially
line1 = go.layout.Shape(
type="line",
x0=fit['tAtm'][start_value_bot], x1=fit['tAtm'][start_value_bot], # Initial position at the first start value
y0=y_min, y1=y_max, # y-range from y_min to y_max
line=dict(color="red", width=1)
)
# Add the second vertical line initially
line2 = go.layout.Shape(
type="line",
x0=fit['tAtm'][start_value_top], x1=fit['tAtm'][start_value_top],
y0=y_min, y1=y_max, # y-range from y_min to y_max
line=dict(color="blue", width=1)
)
# Add the vertical lines to the figure
fig.update_layout(shapes=[line1, line2])
# Add title and axes
fig.update_layout(
title="Select stop point for tensio top and bottom",
xaxis=dict(range=[x_min, x_max]), # Dynamic x-axis range
yaxis=dict(range=[y_min, y_max]), # Dynamic y-axis range
showlegend=True
)
# Function to update the position of the two vertical bars
def update_line_positions(x_position1, x_position2):
# Clear the old data to only show one graph
fig.data = []
# Add the X_top and X_bot curves to the figure
fig.add_trace(go.Scatter(x=fit['tAtm'], y=fit['X_top'], mode='lines', name='X top'))
fig.add_trace(go.Scatter(x=fit['tAtm'], y=fit['X_bot'], mode='lines', name='X bot'))
# Update the figure with the new bar positions
fig.update_layout(
shapes=[
go.layout.Shape(
type="line",
x0=x_position1, x1=x_position1, # Position of the first bar modified
y0=y_min, y1=y_max, # y-range from y_min to y_max
line=dict(color="blue", width=1)
),
go.layout.Shape(
type="line",
x0=x_position2, x1=x_position2, # Position of the second bar modified
y0=y_min, y1=y_max, # y-range from y_min to y_max
line=dict(color="red", width=1)
)
]
)
# Show the updated figure again
fig.show()
# Create a slider to move the first bar between 1 and 7 on the x-axis
slider_x1 = widgets.FloatSlider(value=fit['tAtm'][start_value_top], min=x_min, max=x_max, step=0.01, description='Stop top tension')
# Create a second slider to move the second bar between 1 and 7 on the x-axis
slider_x2 = widgets.FloatSlider(value=fit['tAtm'][start_value_bot], min=x_min, max=x_max, step=0.01, description='Stop bottom tension',)
# Use interact to link the two sliders to the function that updates the bars' positions
interact(update_line_positions, x_position1=slider_x1, x_position2=slider_x2)
введите здесь описание изображения
Я знаю, что это как-то связано с местом расположения функции fig.show(), но не понял, где это сделать. разместите правильно.
Заранее спасибо за помощь
Я пытаюсь создать интерактивный график с помощью Plotly, но он продолжает печатать два графика вместо одного. Вот код, который я использую, и результат, который я получил : [code]# Initialize the position of the bar with the first start value start_value_bot = plateaus_bot[0][0] # First start value in plateaus_bot start_value_top = plateaus_top[0][0] # First start value in plateaus_top
# Calculate the limits for the x and y axes based on the values of X_top and X_bot x_min = min(fit['tAtm']) x_max = max(fit['tAtm']) y_min = min(fit['X_bot'].min(), fit['X_top'].min()) # The minimum value between X_bot and X_top y_max = max(fit['X_bot'].max(), fit['X_top'].max()) + 100 # The maximum value between X_bot and X_top
# Create the initial figure with FigureWidget fig = go.FigureWidget()
# Add the X_top and X_bot curves fig.add_trace(go.Scatter(x=fit['tAtm'], y=fit['X_top'], mode='lines', name='X top')) fig.add_trace(go.Scatter(x=fit['tAtm'], y=fit['X_bot'], mode='lines', name='X bot'))
# Add the first vertical line initially line1 = go.layout.Shape( type="line", x0=fit['tAtm'][start_value_bot], x1=fit['tAtm'][start_value_bot], # Initial position at the first start value y0=y_min, y1=y_max, # y-range from y_min to y_max line=dict(color="red", width=1) )
# Add the second vertical line initially line2 = go.layout.Shape( type="line", x0=fit['tAtm'][start_value_top], x1=fit['tAtm'][start_value_top], y0=y_min, y1=y_max, # y-range from y_min to y_max line=dict(color="blue", width=1) )
# Add the vertical lines to the figure fig.update_layout(shapes=[line1, line2])
# Add title and axes fig.update_layout( title="Select stop point for tensio top and bottom", xaxis=dict(range=[x_min, x_max]), # Dynamic x-axis range yaxis=dict(range=[y_min, y_max]), # Dynamic y-axis range showlegend=True )
# Function to update the position of the two vertical bars def update_line_positions(x_position1, x_position2): # Clear the old data to only show one graph fig.data = [] # Add the X_top and X_bot curves to the figure fig.add_trace(go.Scatter(x=fit['tAtm'], y=fit['X_top'], mode='lines', name='X top')) fig.add_trace(go.Scatter(x=fit['tAtm'], y=fit['X_bot'], mode='lines', name='X bot')) # Update the figure with the new bar positions fig.update_layout( shapes=[ go.layout.Shape( type="line", x0=x_position1, x1=x_position1, # Position of the first bar modified y0=y_min, y1=y_max, # y-range from y_min to y_max line=dict(color="blue", width=1) ), go.layout.Shape( type="line", x0=x_position2, x1=x_position2, # Position of the second bar modified y0=y_min, y1=y_max, # y-range from y_min to y_max line=dict(color="red", width=1) ) ] ) # Show the updated figure again fig.show()
# Create a slider to move the first bar between 1 and 7 on the x-axis slider_x1 = widgets.FloatSlider(value=fit['tAtm'][start_value_top], min=x_min, max=x_max, step=0.01, description='Stop top tension')
# Create a second slider to move the second bar between 1 and 7 on the x-axis slider_x2 = widgets.FloatSlider(value=fit['tAtm'][start_value_bot], min=x_min, max=x_max, step=0.01, description='Stop bottom tension',)
# Use interact to link the two sliders to the function that updates the bars' positions interact(update_line_positions, x_position1=slider_x1, x_position2=slider_x2) [/code] введите здесь описание изображения Я знаю, что это как-то связано с местом расположения функции fig.show(), но не понял, где это сделать. разместите правильно. Заранее спасибо за помощь
У меня есть функция кнопки, которая использует filedialog.askopenfilename для чтения данных из типов файлов XLS, XLSX, DPT, XY и TXT в DataFrame Pandas. Когда я использую кнопку и открываю что -нибудь, кроме файлов XLS или XLSX, я получаю ошибку,...
Я пытаюсь построить региональную карту с реками и контурами озер с помощью карты. Это привлекает несуществующую часть реки внутри озера. См. Изображение Bellow:
Код следующим образом:
import cartopy.crs as ccrsimport cartopy.feature as cfeature...
Я пытаюсь построить региональную карту с реками и контурами озер с помощью карты. Это привлекает несуществующую часть реки внутри озера. См. Изображение Bellow:
Код следующим образом:
import cartopy.crs as ccrsimport cartopy.feature as cfeature...
Я пытаюсь отобразить графики в блокноте с помощью встроенной команды %matplotlib.
Но блокнот не отображает графики, пока не будет вызван plt.show() .
Код, который я запускаю:
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline...
Я работаю над игрой в Unity, но недавно столкнулся с необъяснимой ошибкой, которая появляется, когда я пытаюсь редактировать компоненты дочернего элемента GO.
item.transform.GetChild(0).GetComponent().sprite =...