Ich stehe vor einem Problem, wie im Bild unten gezeigt. Ich versuche, das Balkendiagramm basierend auf den Behandlungen als Gruppe und basierend auf dem Dropdown-Menü zu erstellen. Wenn ich die Auswahl einer Behandlung aufhebe, sollte der Balken verschwinden und die Balken davon anzeigen Verbleibende Behandlungen. Wenn ich jedoch eine Behandlung abwähle, entstehen Lücken. Wie Sie sie vermeiden können, helfen Sie bitte
def plot_(data,selected_trt):
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import streamlit as st
# Create the bar chart
plt.figure(figsize=(10, 7))
# plt.barh(data['USUBJID_numeric'], data['max_ady'], color='skyblue', edgecolor='black', alpha=0.8)
data = data[data['TRT01P'].isin(selected_trt)]
# Example dataset (replace with your data's column of treatment groups)
unique_treatments = data['TRT01P'].unique()
# Define a set of colors (expand or change as needed)
color_palette = plt.cm.Pastel1.colors # Use a colormap (e.g., Pastel1, Set2, etc.)
num_colors = len(color_palette)
# Generate the treatment_colors dictionary dynamically
treatment_colors = {
treatment: color_palette[i % num_colors] # Cycle through the color palette if treatments exceed colors
for i, treatment in enumerate(unique_treatments)
}
# Assign colors based on the treatment group
data['color'] = data['TRT01P'].map(treatment_colors)
xupper = data['max_ady'].max()
# Create the bar chart
plt.figure(figsize=(10, 7))
# for _, row in data.iterrows():
for _, row in data.iterrows():
plt.barh(
row['USUBJID_numeric'], # Subject on the y-axis
row['max_ady'], # Days of treatment on the x-axis
color=row['color'], # Color based on treatment group
edgecolor='black',
alpha=0.8
)
legend_elements = [
Line2D([0], [0], color=color, lw=4, label=treatment)
for treatment, color in treatment_colors.items()
]
plt.legend(handles=legend_elements, title='Treatments', loc='best')
# Update the y-axis ticks to show original USUBJID values
plt.yticks(data['USUBJID_numeric'], data['USUBJID'])
# Add labels and title
plt.xlabel('Days of Treatment')
plt.ylabel('Subjects')
# plt.title('Swimmer Plot for Treatment Exposure')
# Adjust axis limits to start at (0, 0)
plt.margins(x=0, y=0.01)
ax = plt.gca()
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.xlim(0, xupper+100)
# Display the plot in Streamlit
st.pyplot(plt.gcf())
Ich stehe vor einem Problem, wie im Bild unten gezeigt. Ich versuche, das Balkendiagramm basierend auf den Behandlungen als Gruppe und basierend auf dem Dropdown-Menü zu erstellen. Wenn ich die Auswahl einer Behandlung aufhebe, sollte der Balken verschwinden und die Balken davon anzeigen Verbleibende Behandlungen. Wenn ich jedoch eine Behandlung abwähle, entstehen Lücken. Wie Sie sie vermeiden können, helfen Sie bitte [img]https://i.sstatic.net/AJ9sj9k8.png[/img]
[code]def plot_(data,selected_trt): import matplotlib.pyplot as plt from matplotlib.lines import Line2D import streamlit as st
# Create the bar chart plt.figure(figsize=(10, 7)) # plt.barh(data['USUBJID_numeric'], data['max_ady'], color='skyblue', edgecolor='black', alpha=0.8)
data = data[data['TRT01P'].isin(selected_trt)]
# Example dataset (replace with your data's column of treatment groups) unique_treatments = data['TRT01P'].unique()
# Define a set of colors (expand or change as needed) color_palette = plt.cm.Pastel1.colors # Use a colormap (e.g., Pastel1, Set2, etc.) num_colors = len(color_palette)
# Generate the treatment_colors dictionary dynamically treatment_colors = { treatment: color_palette[i % num_colors] # Cycle through the color palette if treatments exceed colors for i, treatment in enumerate(unique_treatments) }
# Assign colors based on the treatment group data['color'] = data['TRT01P'].map(treatment_colors) xupper = data['max_ady'].max()
# Create the bar chart plt.figure(figsize=(10, 7))
# for _, row in data.iterrows(): for _, row in data.iterrows(): plt.barh( row['USUBJID_numeric'], # Subject on the y-axis row['max_ady'], # Days of treatment on the x-axis color=row['color'], # Color based on treatment group edgecolor='black', alpha=0.8 )
legend_elements = [ Line2D([0], [0], color=color, lw=4, label=treatment) for treatment, color in treatment_colors.items() ] plt.legend(handles=legend_elements, title='Treatments', loc='best') # Update the y-axis ticks to show original USUBJID values plt.yticks(data['USUBJID_numeric'], data['USUBJID'])
# Add labels and title plt.xlabel('Days of Treatment') plt.ylabel('Subjects') # plt.title('Swimmer Plot for Treatment Exposure') # Adjust axis limits to start at (0, 0) plt.margins(x=0, y=0.01) ax = plt.gca() ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) plt.xlim(0, xupper+100)
# Display the plot in Streamlit st.pyplot(plt.gcf()) [/code]
Ich habe RA- und DEC -Zeigendaten, die ich auf einem polaren Diagramm zeigen möchte (Konvertierung in Rho und Theta).
Die Theta -Bewegung ist sehr klein, ~ 0,01 Grad. Dies ist in einem vollständigen...
Auf einer neu erstellten WPF -App befindet sich eine schwarze Balken, einschließlich Schaltflächen wie Live Visual Tree . Wie kann ich es loswerden? Es ist nicht mehr da.
Ich arbeite daran, ein Diagramm zu erstellen und die Datenbank mit C# WPF nachzuschlagen.
Es ist mir gelungen, die Datenbanksuche und das Diagramm durchzuführen.
Ist es möglich, ein Diagramm zu...
Ich arbeite daran, ein Diagramm zu erstellen und die Datenbank mit C# WPF nachzuschlagen. Es ist mir gelungen, die DB-Suche und das Diagramm durchzuführen.
Ist es möglich, ein Diagramm dieser Form...
Ich versuche, ein Diagramm einer Funktion f (x, y) = x ** x*y zu zeichnen, aber ich erhalte einen Fehler:
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D...