Python Forum
Plotting help! Time is of the essence
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plotting help! Time is of the essence
#1
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
Reply
#2
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
Reply
#3
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!
Reply
#4
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
Reply
#5
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>
Reply
#6
Thank you.
Reply
#7
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Plotting by Time, error mansoorahs 1 707 May-16-2023, 09:46 AM
Last Post: Larz60+
  Non-blocking real-time plotting slow_rider 5 3,455 Jan-07-2023, 09:47 PM
Last Post: woooee
  time setup for realtime plotting of serial datas at high sampling rate alice93 6 3,649 Jan-07-2022, 05:41 PM
Last Post: deanhystad
  Plotting A Time Series With Shaded Recession Bars adamszymanski 1 3,119 Jan-24-2021, 09:08 PM
Last Post: nealc
  save in CSV and plotting in real time linkxxx 8 5,550 Sep-01-2019, 12:24 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020