Python Forum

Full Version: Plotting help! Time is of the essence
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I seem to be having an issue with plotting a figure correctly. it brings up the error that: ValueError: Image size of 1215624718x1259970318 pixels is too large. It must be less than 2^16 in each direction. The point is to plot the moon and Earth and plot a rocket flying around them in an orbit slingshot sorta way.

        Earth = plt.Circle((0, 0), 6378000, color ='g', label = 'Earth')
        Moon = plt.Circle((0, 384e6), 1737000, color ='grey', label='Moon')
        plt.gcf().add_artist(Earth)
        plt.gcf().add_artist(Moon)
        plt.plot(xlist, ylist, color='b', label='Journey')
        plt.legend(loc='lower right')
        plt.xlabel('x-position (m)')
        plt.ylabel('y-position (m)')
        plt.ylim((3.5e8, 4e8))
        plt.xlim((-0.2e8,0.2e8))
        plt.axis('equal')
        plt.grid()
        plt.show()
Could anyone help? Thanks for your time
Quote: it brings up the error that
It would be nice to know what 'it' is. I assume matplotlib?
Also, please show error traceback message unaltered and complete using BBcode tags
Sorry yes it is matplotlib, i'm new to python and this forum. i don't know what BBcode is but the full error for this section is below:


File "<ipython-input-9-3d28e2a5b1b3>", line 1, in <module>
runfile('C:/Users/Imad/Desktop/ex4.py', wdir='C:/Users/Imad/Desktop')

File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile
execfile(filename, namespace)

File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/Imad/Desktop/ex4.py", line 341, in <module>
corners = ((x1, y1), (x2, y2))

NameError: name 'x1' is not defined

Traceback (most recent call last):

File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\formatters.py", line 341, in __call__
return printer(obj)

File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 244, in <lambda>
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))

File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 128, in print_figure
fig.canvas.print_figure(bytes_io, **kw)

File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 2075, in print_figure
**kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 510, in print_png
FigureCanvasAgg.draw(self)

File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 396, in draw
self.renderer = self.get_renderer(cleared=True)

File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 417, in get_renderer
self.renderer = RendererAgg(w, h, self.figure.dpi)

File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 87, in __init__
self._renderer = _RendererAgg(int(width), int(height), dpi)

ValueError: Image size of 1215624718x1259970318 pixels is too large. It must be less than 2^16 in each direction.

<Figure size 432x288 with 2 Axes>


Thanks again!
Quote:i don't know what BBcode is but the full error for this section is below:
Click on the link: BBcode and learn please. Forum rules.

run migration (twice) shown in post 2
Like so?

        
        Earth = plt.Circle((0, 0), 6378000, color ='g', label = 'Earth')
        Moon = plt.Circle((0, 384e6), 1737000, color ='grey', label='Moon')
        plt.gcf().add_artist(Earth)
        plt.gcf().add_artist(Moon)
        plt.plot(xlist, ylist, color='b', label='Journey')
        plt.legend(loc='lower right')
        plt.xlabel('x-position (m)')
        plt.ylabel('y-position (m)')
        plt.ylim((3.5e8, 4e8))
        plt.xlim((-0.2e8,0.2e8))
        plt.axis('equal')
        plt.grid()
        plt.show()
    
Error:
File "<ipython-input-9-3d28e2a5b1b3>", line 1, in <module> runfile('C:/Users/Imad/Desktop/ex4.py', wdir='C:/Users/Imad/Desktop') File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile execfile(filename, namespace) File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/Imad/Desktop/ex4.py", line 341, in <module> corners = ((x1, y1), (x2, y2)) NameError: name 'x1' is not defined Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\formatters.py", line 341, in __call__ return printer(obj) File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 244, in <lambda> png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs)) File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 128, in print_figure fig.canvas.print_figure(bytes_io, **kw) File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 2075, in print_figure **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 510, in print_png FigureCanvasAgg.draw(self) File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 396, in draw self.renderer = self.get_renderer(cleared=True) File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 417, in get_renderer self.renderer = RendererAgg(w, h, self.figure.dpi) File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 87, in __init__ self._renderer = _RendererAgg(int(width), int(height), dpi) ValueError: Image size of 1215624718x1259970318 pixels is too large. It must be less than 2^16 in each direction. <Figure size 432x288 with 2 Axes>
Thank you.
You can try to continue with the following piece of code:

i
mport matplotlib.pyplot as plt
# ---------- Constants ----------
SCALE = 10**6
EARTH_RADIUS  = 6378000 / SCALE
MOON_RADIUS = 1737000 / SCALE
MOON_DIST = 384e6 / SCALE
# -------------------------------

fig = plt.figure()
ax = fig.add_subplot(111)
Earth = plt.Circle((0, 0), EARTH_RADIUS, color='g', label = 'Earth')
Moon = plt.Circle((0, MOON_DIST), MOON_RADIUS, color ='r', label='Moon')
ax.add_artist(Moon)
ax.add_artist(Earth)
plt.xlabel('x-position (Mm)')
plt.ylabel('y-position (Mm)')
plt.xlim(-10 ** 7 / SCALE, 10**8 / SCALE)
plt.ylim(-10 ** 7 / SCALE, 4* 10**8 / SCALE)
ax.set_aspect('equal')
plt.grid()
plt.show()
AFAIK, Matplotlib is designed to make publication ready figures. It is possible to create
animation using Matplotlib, but it is not primarily designed for this.