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

معرفة حجم الشكل figure باستخدام Matplotrlib في بايثون

Ali Ismael

السؤال

Recommended Posts

  • 0

يمكنك القيام بذلك من خلال استخدام الدالة fig.get_size_inches لإعطاء حجمه بالبوصة ثم  ضربها بقيمة ال dpi للشكل فينتج حجم الشكل بالبكسل، مثال:

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
fig.suptitle('matplotlib.figure.Figure.delaxes() \
function Example\n\n', fontweight ="bold")
size = fig.get_size_inches()*fig.dpi
print("size in pixels:",size)
# الخرج
# size in pixels: [432. 288.]

في حال كان لديك أكثر من شكل فقط قم بالتعديل التالي:

fig = plt.gcf()
size = fig.get_size_inches()*fig.dpi

أو بشكل التالي:

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
fig.suptitle('matplotlib.figure.Figure.size in pixels \
 Example\n\n', fontweight ="bold")
bbox = fig.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
width, height = bbox.width*fig.dpi, bbox.height*fig.dpi
print(bbox)
print(width)
print(height)
"""
Bbox(x0=0.0, y0=0.0, x1=6.0, y1=4.0)
432.0
288.0
"""
رابط هذا التعليق
شارك على الشبكات الإجتماعية

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

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

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

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   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.

  • إعلانات

  • تابعنا على



×
×
  • أضف...