Ich versuche eine Dash -Anwendung zu erstellen, in der ein Gitter von Nebenhandlungen angezeigt wird, um den paarweisen Vergleich der Spalten eines Datenrahmens zu visualisieren. Oben und links in jeder Rasterreihe und der Spalte befinden sich die entsprechenden Variablen. Die Variablennamen können jedoch ziemlich lang sein, daher ist es einfach, sie falsch auszurichten. Ich habe es versucht, die Variablennamen zu taumeln, sie aber schließlich auf der Linie eingeschaltet, um sie zu übertreffen. Siehe das Bild unten. Ich habe auch meinen Code am Ende dieses Beitrags < /p> aufgenommen
import dash
from dash import dcc, html
import pandas as pd
import plotly.express as px
import plotly.subplots as sp
import numpy as np
import plotly.graph_objects as go
# Sample DataFrame
df = pd.DataFrame({
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA": ["1", "2", "3", "4"],
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB": ["2024-01-01", "2024-01-02", "2024-01-03", "2024-01-04"],
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC": ["cat", "dog", "cat", "mouse"],
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD": ["10.5", "20.3", "30.1", "40.2"],
'EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE': ['apple', 'apple', 'apple', 'banana']
})
# Convert data types
def convert_dtypes(df):
for col in df.columns:
try:
df[col] = pd.to_numeric(df[col]) # Convert to int/float
except ValueError:
try:
df[col] = pd.to_datetime(df[col]) # Convert to datetime
except ValueError:
df[col] = df[col].astype("string") # Keep as string
return df
df = convert_dtypes(df)
columns = df.columns
num_cols = len(columns)
# Dash App
app = dash.Dash(__name__)
app.layout = html.Div([
html.H1("Pairwise Column Plots"),
dcc.Graph(id='grid-plots')
])
@app.callback(
dash.Output('grid-plots', 'figure'),
dash.Input('grid-plots', 'id') # Dummy input to trigger callback
)
def create_plot_grid(_):
fig = sp.make_subplots(rows = num_cols, cols = num_cols,
#subplot_titles = [f"{x} vs {y}" for x in columns for y in columns],
shared_xaxes = False, shared_yaxes = False)
annotations = [] # Store subplot titles dynamically
# Add column labels (Top Labels)
for j, col_label in enumerate(columns):
annotations.append(
dict(
#text=f"{col_label}[/b]", # Bold for emphasis[b] text=f"{'
'.join(col_label[x:x+10] for x in range(0, len(col_label), 10))}[/b]",[b] xref = "paper", yref = "paper",
x = (j) / num_cols, # Center over the column
y = 1.02, # Slightly above the top row
showarrow = False,
font = dict(size = 14, color = "black")
)
)
# Add row labels (Side Labels)
for i, row_label in enumerate(columns):
annotations.append(
dict(
#text = f"{row_label}[/b]", # Bold for emphasis[b] text=f"{'
'.join(row_label[x:x+10] for x in range(0, len(row_label), 10))}[/b]",
xref = "paper", yref = "paper",
x = -0.02, # Slightly to the left of the row
y = (1 - (i + 0.5) / num_cols), # Center next to the row
showarrow = False,
font = dict(size = 14, color = "black"),
textangle = -90 # Rotate text for vertical orientation
)
)
print(annotations)
for i, x_col in enumerate(columns):
for j, y_col in enumerate(columns):
dtype_x, dtype_y = df[x_col].dtype, df[y_col].dtype
row, col = i + 1, j + 1 # Adjust for 1-based indexing
# I only want to print the upper triangle of the grid
if j
Ich versuche eine Dash -Anwendung zu erstellen, in der ein Gitter von Nebenhandlungen angezeigt wird, um den paarweisen Vergleich der Spalten eines Datenrahmens zu visualisieren. Oben und links in jeder Rasterreihe und der Spalte befinden sich die entsprechenden Variablen. Die Variablennamen können jedoch ziemlich lang sein, daher ist es einfach, sie falsch auszurichten. Ich habe es versucht, die Variablennamen zu taumeln, sie aber schließlich auf der Linie eingeschaltet, um sie zu übertreffen. Siehe das Bild unten. Ich habe auch meinen Code am Ende dieses Beitrags < /p> [b] aufgenommen[code]df = pd.DataFrame({ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA": ["1", "2", "3", "4"], "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB": ["2024-01-01", "2024-01-02", "2024-01-03", "2024-01-04"], "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC": ["cat", "dog", "cat", "mouse"], "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD": ["10.5", "20.3", "30.1", "40.2"], 'EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE': ['apple', 'apple', 'apple', 'banana'] }) [/code] Für diesen Datenrahmen würde ich gerne so etwas wie
[code]import dash from dash import dcc, html import pandas as pd import plotly.express as px import plotly.subplots as sp import numpy as np import plotly.graph_objects as go
@app.callback( dash.Output('grid-plots', 'figure'), dash.Input('grid-plots', 'id') # Dummy input to trigger callback ) def create_plot_grid(_): fig = sp.make_subplots(rows = num_cols, cols = num_cols, #subplot_titles = [f"{x} vs {y}" for x in columns for y in columns], shared_xaxes = False, shared_yaxes = False)
annotations = [] # Store subplot titles dynamically # Add column labels (Top Labels) for j, col_label in enumerate(columns): annotations.append( dict( #text=f"{col_label}[/b]", # Bold for emphasis[b] text=f"{' '.join(col_label[x:x+10] for x in range(0, len(col_label), 10))}[/b]",[b] xref = "paper", yref = "paper", x = (j) / num_cols, # Center over the column y = 1.02, # Slightly above the top row showarrow = False, font = dict(size = 14, color = "black") ) ) # Add row labels (Side Labels) for i, row_label in enumerate(columns): annotations.append( dict( #text = f"{row_label}[/b]", # Bold for emphasis[b] text=f"{' '.join(row_label[x:x+10] for x in range(0, len(row_label), 10))}[/b]", xref = "paper", yref = "paper", x = -0.02, # Slightly to the left of the row y = (1 - (i + 0.5) / num_cols), # Center next to the row showarrow = False, font = dict(size = 14, color = "black"), textangle = -90 # Rotate text for vertical orientation ) )
print(annotations)
for i, x_col in enumerate(columns): for j, y_col in enumerate(columns): dtype_x, dtype_y = df[x_col].dtype, df[y_col].dtype row, col = i + 1, j + 1 # Adjust for 1-based indexing
# I only want to print the upper triangle of the grid if j
Ich habe Probleme, das korrekte Ergebnis aus der DEF „Calculed_Value_M1“ zu erhalten, die die obigen DEFs aufruft. Wie kann ich es lösen?
def calc_objetivo_c(row):
temp_prod = row.get( Temp Prod ,...
Ich habe im Internet viele ähnliche Fragen gefunden, aber keine hat genau das gleiche Problem. Ich habe auch einige dieser Lösungen ausprobiert, aber es hat nicht geklappt.
I Ich erstelle eine...
Ich habe ein Dash-Plot-Diagramm (siehe unten Link), das das Inspektionsdatum auf der X-Achse und die Punktzahl auf der y-Achse anzeigt. Mein Ziel ist es, die Y-Achse zwischen Punktzahl und Punkten zu...