How to remove padding between the plot and window

I’m trying to rebuild the solar system in a 3D – koordinate system. I build one sphere as the sun and multiple circles (orbits) around it with sphere as planets. But I don’t know how I can remove the padding between the plot and window so you can see the right and left side of the orbit.

Picture – Solar System but the outer orbits are cut out on the left and right

`

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

scale_distance = 1/10000000
scale_sphere = 1/2

fig, ax = None

class tool():
    def __init__(self, fig, ax):
        self.fig = fig
        self.ax = ax

    def create_fig(self, facecolor, figsize=(16, 9)):
        self.fig = plt.figure(facecolor=facecolor, figsize=figsize)
        self.ax = self.fig.add_subplot(111, projection='3d')
        self.ax.set_facecolor(facecolor)
        return self.fig, self.ax    
    
    def set_axis_off(self):
        self.ax.grid(False)
        self.ax.set_xticks([])
        self.ax.set_yticks([])
        self.ax.set_zticks([])
        self.ax.set_xlabel('')
        self.ax.set_ylabel('')
        self.ax.set_zlabel('')
        self.ax.set_axis_off()
        return self.ax

    def set_axis_limits(self, size_koordsystem):
        self.ax.set_box_aspect([1, 1, 1])
        self.ax.set_xlim([size_koordsystem, size_koordsystem])
        self.ax.set_ylim([size_koordsystem, size_koordsystem])
        self.ax.set_zlim([size_koordsystem,size_koordsystem])
        return self.ax
    

class sphere():
    def __init__(self, u, v):
        self.u = u
        self.v = v

    def values_for_sphere(self):
        x = np.outer(np.cos(self.u), np.sin(self.v))
        y = np.outer(np.sin(self.u), np.sin(self.v))
        z = np.outer(np.ones(np.size(self.u)), np.cos(self.v))
        return x, y, z
    
    def plot_sphere(self, ax, rs, cr, color, alpha, x_offset=0, y_offset=0, z_offset=0):
        x, y, z = self.values_for_sphere()
        ax.plot_surface(x+x_offset, y+y_offset, z+z_offset, rstride=rs, cstride=cr, color=color, alpha=alpha)
        return ax


class orbit():
    def __init__(self, a_planet):
        self.a_planet = a_planet

    def values_for_orbit(self, a_planet, e):
        if a_planet is None:
            raise ValueError("Der Planetenradius darf nicht None sein.")
        if not (0 <= e < 1):
            raise ValueError("Die Exzentrizität muss zwischen 0 und 1 liegen.")
        a_planet = a_planet * scale_distance
        a = np.linspace(0, 2 * np.pi, 100)
        x_orbit = a_planet * np.cos(a)
        y_orbit = a_planet * np.sqrt(1 - e**2) * np.sin(a)
        return x_orbit, y_orbit

    def plot_orbit(self, ax, a_planet, e, color, alpha):
        x_orbit, y_orbit = self.values_for_orbit(a_planet, e)
        ax.plot(x_orbit, y_orbit, 0, color=color, alpha=alpha)
        return ax

planets = [
    ["Merkur", 57.90, 0.2056, 0.24, 3.3011e23, 2.439, 7*np.pi/180],
    ["Venus", 108.21e6, 0.0067, 0.62, 4.8675e24, 6.052, 3.39*np.pi/180],
    ["Erde", 146.6e6, 0.0167, 1.00, 5.97237e24,6.371, 0],
    ["Mars", 227.9e6, 0.0934, 1.88, 6.4171e23, 3.389, 1.85*np.pi/180],
    ["Jupiter", 778.57e6, 0.0483, 11.86, 1.8982e27, 69.911, 1.305*np.pi/180],
    ["Saturn", 1433.53e6, 0.0541, 29.46, 5.6834e26, 58.232, 2.485*np.pi/180],
    ["Uranus", 2872.46e6, 0.0471, 84.01, 8.6810e25, 25.362, 0.772*np.pi/180],
    ["Neptun", 4497.06e6, 0.0085, 164.79, 1.02413e26, 24.622, 1.769 *np.pi/180],
]

for planet in planets:
    e = planet[2]
    if not (0 <= e < 1):
        raise ValueError(f"Die Exzentrizität von {planet[0]} muss zwischen 0 und 1 liegen, aber sie ist {e}.")
    
universe = tool(fig, ax)
fig, ax = universe.create_fig('black')
universe.set_axis_off()
universe.set_axis_limits(100)

sun = sphere(np.linspace(0, 2 * np.pi, 100), np.linspace(0, np.pi, 200))
sun.plot_sphere(ax, 4, 4, 'y', 0.5)

for planet in planets:
    r_planet = planet[5] * scale_sphere
    a_planet = planet[1]
    planet = sphere(r_planet * np.linspace(0, 2 * np.pi, 100), r_planet * np.linspace(0, np.pi, 100))
    planet.plot_sphere(ax, 4, 4, 'r', 0.5, x_offset=a_planet*scale_distance)

for planet in planets:
    a_planet = planet[1]
    e = planet[2]
    orbit_planet = orbit(a_planet)
    orbit_planet.plot_orbit(ax, a_planet, e, 'w', 0.5)

fig.tight_layout()
fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
fig.subplots_adjust(wspace=0, hspace=0)

plt.show()



`

I already tried these functions:

fig.subplots_adjust(left=0, right=1, top=1, bottom=0)

fig.subplots_adjust(wspace=0, hspace=0)

Why is there still a left and right pattern. I set the window to figsize=(16, 9)

New contributor

Silas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

There is an error when you set up your limits per each axis, for example:

ax.set_xlim(min,max)

expects two values while in your code you are setting them to the same value

a quick solution would be to adjust your code as

self.ax.set_xlim([-size_koordsystem, size_koordsystem])

if your plot is centered at 0,0 and expands in three dimensions symetrically.

using universe.set_axis_limits(290)

it produces the following result where all the orbits can be seen

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật