اذهب إلى المحتوى

السؤال

نشر

السلام عليكم

# Set the overall figure size
plt.figure(figsize=(12, 11))

# Plot 1: age_at_hct vs gvhd_proph
plt.subplot(2, 2, 1)

sns.histplot(data=data_train, x='age_at_hct', hue='gvhd_proph', multiple='stack', palette='Blues')
plt.title("Stacked Histogram of Age at HCT and GVHD Prophylaxis")
plt.xlabel("Age at HCT")
plt.ylabel("Count")

# Plot 1: age_at_hct vs tbi_status
plt.subplot(2,2,2)

sns.histplot(data=data_train, x='age_at_hct', hue='tbi_status', multiple='stack', palette='Blues')
plt.title("Stacked Histogram of Age at HCT and Tbi-Status")
plt.xlabel("Age at HCT")
plt.ylabel("Count")

plt.tight_layout()
plt.show()

ودي الرسم 

المشكله في الرسم الاول عمود الgvhd_proph داخل جوه الرسم فا ازي احل المشكله دي و يكون العمود بر الرسم ؟

 

Distribution-of-EFS-EFS-Time.png

Recommended Posts

  • 0
نشر

مرحبًا،

يجب أن يكون استعمال bbox_to_anchor مناسب لحل مشكلتك، يمكننا وضعه في أول الرسم البياني بحيث يكون فوق الرسم.

جرب استعمال الكود التالي و أخبرني بالنتيجة:

import matplotlib.pyplot as plt
import seaborn as sns

# Assuming 'data_train' is your DataFrame

# Set the overall figure size
plt.figure(figsize=(12, 11))

# Plot 1: age_at_hct vs gvhd_proph
plt.subplot(2, 2, 1)
sns.histplot(data=data_train, x='age_at_hct', hue='gvhd_proph', multiple='stack', palette='Blues')
plt.title("Stacked Histogram of Age at HCT and GVHD Prophylaxis")
plt.xlabel("Age at HCT")
plt.ylabel("Count")
plt.legend(bbox_to_anchor=(1, 1), loc='upper left')  # Move legend outside

# Plot 1: age_at_hct vs tbi_status
plt.subplot(2, 2, 2)
sns.histplot(data=data_train, x='age_at_hct', hue='tbi_status', multiple='stack', palette='Blues')
plt.title("Stacked Histogram of Age at HCT and Tbi-Status")
plt.xlabel("Age at HCT")
plt.ylabel("Count")
plt.legend(bbox_to_anchor=(1, 1), loc='upper left')  # Move legend outside

plt.tight_layout()
plt.show()

تحياتي.

  • 0
نشر
بتاريخ 3 ساعة قال Kais Hasan:

مرحبًا،

يجب أن يكون استعمال bbox_to_anchor مناسب لحل مشكلتك، يمكننا وضعه في أول الرسم البياني بحيث يكون فوق الرسم.

جرب استعمال الكود التالي و أخبرني بالنتيجة:

import matplotlib.pyplot as plt
import seaborn as sns

# Assuming 'data_train' is your DataFrame

# Set the overall figure size
plt.figure(figsize=(12, 11))

# Plot 1: age_at_hct vs gvhd_proph
plt.subplot(2, 2, 1)
sns.histplot(data=data_train, x='age_at_hct', hue='gvhd_proph', multiple='stack', palette='Blues')
plt.title("Stacked Histogram of Age at HCT and GVHD Prophylaxis")
plt.xlabel("Age at HCT")
plt.ylabel("Count")
plt.legend(bbox_to_anchor=(1, 1), loc='upper left')  # Move legend outside

# Plot 1: age_at_hct vs tbi_status
plt.subplot(2, 2, 2)
sns.histplot(data=data_train, x='age_at_hct', hue='tbi_status', multiple='stack', palette='Blues')
plt.title("Stacked Histogram of Age at HCT and Tbi-Status")
plt.xlabel("Age at HCT")
plt.ylabel("Count")
plt.legend(bbox_to_anchor=(1, 1), loc='upper left')  # Move legend outside

plt.tight_layout()
plt.show()

تحياتي.

هي  اختفيت مش موجود 

Distribution-of-EFS-EFS-Time.png

  • 0
نشر
بتاريخ 13 دقائق مضت قال Ali Ahmed55:

هي  اختفيت مش موجود 

قمت بتجربة الكود لديك ولا يوجد مشكلة، أرجو تجربة التالي:

Snag_aeb189d.thumb.png.13859d9aa12f626dd3f6ab2013450750.png

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np

# توليد بيانات مؤقتة
np.random.seed(42)
data_train = pd.DataFrame({
    'age_at_hct': np.random.normal(50, 15, 500),
    'gvhd_proph': np.random.choice([0, 1], 500),
    'tbi_status': np.random.choice(['No', 'Yes'], 500)
})

plt.figure(figsize=(12, 11))

plt.subplot(2, 2, 1)

sns.histplot(data=data_train, x='age_at_hct', hue='gvhd_proph', multiple='stack', palette='Blues')
plt.title("Stacked Histogram of Age at HCT and GVHD Prophylaxis")
plt.xlabel("Age at HCT")
plt.ylabel("Count")

plt.subplot(2,2,2)

sns.histplot(data=data_train, x='age_at_hct', hue='tbi_status', multiple='stack', palette='Blues')
plt.title("Stacked Histogram of Age at HCT and Tbi-Status")
plt.xlabel("Age at HCT")
plt.ylabel("Count")

plt.tight_layout()
plt.show()

 

  • 0
نشر
بتاريخ 14 ساعة قال Mustafa Suleiman:

قمت بتجربة الكود لديك ولا يوجد مشكلة، أرجو تجربة التالي:

Snag_aeb189d.thumb.png.13859d9aa12f626dd3f6ab2013450750.png

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np

# توليد بيانات مؤقتة
np.random.seed(42)
data_train = pd.DataFrame({
    'age_at_hct': np.random.normal(50, 15, 500),
    'gvhd_proph': np.random.choice([0, 1], 500),
    'tbi_status': np.random.choice(['No', 'Yes'], 500)
})

plt.figure(figsize=(12, 11))

plt.subplot(2, 2, 1)

sns.histplot(data=data_train, x='age_at_hct', hue='gvhd_proph', multiple='stack', palette='Blues')
plt.title("Stacked Histogram of Age at HCT and GVHD Prophylaxis")
plt.xlabel("Age at HCT")
plt.ylabel("Count")

plt.subplot(2,2,2)

sns.histplot(data=data_train, x='age_at_hct', hue='tbi_status', multiple='stack', palette='Blues')
plt.title("Stacked Histogram of Age at HCT and Tbi-Status")
plt.xlabel("Age at HCT")
plt.ylabel("Count")

plt.tight_layout()
plt.show()

 

ايوه يا أ.مصطفي بس الرسم البياني مش واضح فين العمود الgvhd_proph  و عمود الTbi ال في القيمه البتواضح الرسم البياني ؟

  • 0
نشر
بتاريخ 55 دقائق مضت قال Ali Ahmed55:

ايوه يا أ.مصطفي بس الرسم البياني مش واضح فين العمود الgvhd_proph  و عمود الTbi ال في القيمه البتواضح الرسم البياني ؟

لقد حللت مشكلتك. كان هناك مشكلة في ترك فراغ حتى يمكن رسم ال legends فيه باستعمال الطريقة السابقة.

لكن إبقاء المخططين بجانب  بعضهما سيجعل المخططات متداخلة، لذلك قمت ببعض التنسيق بحيث تظهر المخططات بشكل أفضل:

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from matplotlib.patches import Patch

data_train = pd.read_csv('train.csv')

# Create figure with 2 vertical subplots (2 rows, 1 column)
fig, axes = plt.subplots(2, 1, figsize=(12, 14))  # Increased height for vertical spacing

# -----------------------------------------------------------------
# Plot 1: Top plot (age_at_hct vs gvhd_proph)
# -----------------------------------------------------------------
hue_categories_1 = data_train['gvhd_proph'].unique()
palette_1 = sns.color_palette("Blues", n_colors=len(hue_categories_1))

sns.histplot(
    data=data_train,
    x='age_at_hct',
    hue='gvhd_proph',
    multiple='stack',
    palette=palette_1,
    ax=axes[0],
    legend=False
)
axes[0].set_title("Stacked Histogram of Age at HCT and GVHD Prophylaxis", pad=20)
axes[0].set_xlabel("Age at HCT")
axes[0].set_ylabel("Count")

# Legend for top plot (right side)
legend_patches_1 = [Patch(color=color, label=label) for color, label in zip(palette_1, hue_categories_1)]
axes[0].legend(
    handles=legend_patches_1,
    bbox_to_anchor=(1.05, 1),  # Right side
    loc='upper left',
    title='GVHD Prophylaxis'
)

# -----------------------------------------------------------------
# Plot 2: Bottom plot (age_at_hct vs tbi_status)
# -----------------------------------------------------------------
hue_categories_2 = data_train['tbi_status'].unique()
palette_2 = sns.color_palette("Blues", n_colors=len(hue_categories_2))

sns.histplot(
    data=data_train,
    x='age_at_hct',
    hue='tbi_status',
    multiple='stack',
    palette=palette_2,
    ax=axes[1],
    legend=False
)
axes[1].set_title("Stacked Histogram of Age at HCT and Tbi-Status", pad=20)
axes[1].set_xlabel("Age at HCT")
axes[1].set_ylabel("Count")

# Legend for bottom plot (right side)
legend_patches_2 = [Patch(color=color, label=label) for color, label in zip(palette_2, hue_categories_2)]
axes[1].legend(
    handles=legend_patches_2,
    bbox_to_anchor=(1.05, 1),  # Right side
    loc='upper left',
    title='TBI Status'
)

# -----------------------------------------------------------------
# Final layout adjustments
# -----------------------------------------------------------------
plt.tight_layout()
plt.subplots_adjust(
    hspace=0.3,  # Space between subplots
    right=0.85    # Make space for legends on the right
)

plt.show()

تحياتي.

  • 0
نشر
بتاريخ 5 دقائق مضت قال Kais Hasan:

لقد حللت مشكلتك. كان هناك مشكلة في ترك فراغ حتى يمكن رسم ال legends فيه باستعمال الطريقة السابقة.

لكن إبقاء المخططين بجانب  بعضهما سيجعل المخططات متداخلة، لذلك قمت ببعض التنسيق بحيث تظهر المخططات بشكل أفضل:

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from matplotlib.patches import Patch

data_train = pd.read_csv('train.csv')

# Create figure with 2 vertical subplots (2 rows, 1 column)
fig, axes = plt.subplots(2, 1, figsize=(12, 14))  # Increased height for vertical spacing

# -----------------------------------------------------------------
# Plot 1: Top plot (age_at_hct vs gvhd_proph)
# -----------------------------------------------------------------
hue_categories_1 = data_train['gvhd_proph'].unique()
palette_1 = sns.color_palette("Blues", n_colors=len(hue_categories_1))

sns.histplot(
    data=data_train,
    x='age_at_hct',
    hue='gvhd_proph',
    multiple='stack',
    palette=palette_1,
    ax=axes[0],
    legend=False
)
axes[0].set_title("Stacked Histogram of Age at HCT and GVHD Prophylaxis", pad=20)
axes[0].set_xlabel("Age at HCT")
axes[0].set_ylabel("Count")

# Legend for top plot (right side)
legend_patches_1 = [Patch(color=color, label=label) for color, label in zip(palette_1, hue_categories_1)]
axes[0].legend(
    handles=legend_patches_1,
    bbox_to_anchor=(1.05, 1),  # Right side
    loc='upper left',
    title='GVHD Prophylaxis'
)

# -----------------------------------------------------------------
# Plot 2: Bottom plot (age_at_hct vs tbi_status)
# -----------------------------------------------------------------
hue_categories_2 = data_train['tbi_status'].unique()
palette_2 = sns.color_palette("Blues", n_colors=len(hue_categories_2))

sns.histplot(
    data=data_train,
    x='age_at_hct',
    hue='tbi_status',
    multiple='stack',
    palette=palette_2,
    ax=axes[1],
    legend=False
)
axes[1].set_title("Stacked Histogram of Age at HCT and Tbi-Status", pad=20)
axes[1].set_xlabel("Age at HCT")
axes[1].set_ylabel("Count")

# Legend for bottom plot (right side)
legend_patches_2 = [Patch(color=color, label=label) for color, label in zip(palette_2, hue_categories_2)]
axes[1].legend(
    handles=legend_patches_2,
    bbox_to_anchor=(1.05, 1),  # Right side
    loc='upper left',
    title='TBI Status'
)

# -----------------------------------------------------------------
# Final layout adjustments
# -----------------------------------------------------------------
plt.tight_layout()
plt.subplots_adjust(
    hspace=0.3,  # Space between subplots
    right=0.85    # Make space for legends on the right
)

plt.show()

تحياتي.

بسم الله ما شاء الله 

الف شكراااا جدا جدا  لحضرتكم

جزاكم الله كل خير

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...