theOehrly / Fast-F1

FastF1 is a python package for accessing and analyzing Formula 1 results, schedules, timing data and telemetry
https://docs.fastf1.dev
MIT License
2.49k stars 261 forks source link

[BUG] Displaying Plot #210

Closed karenx8 closed 2 years ago

karenx8 commented 2 years ago

Describe the issue:

I have managed to get all my code working except for displaying the plot graph itself, I used the code displayed above. But I get an error each time that I will provide below. Please help when possible.

Reproduce the code example:

fig, ax = plt.subplots()
ax.plot(lec['LapNumber'], lec['LapTime'], color='red')
ax.plot(ham['LapNumber'], ham['LapTime'], color='cyan')
ax.set_title("LEC vs HAM")
ax.set_xlabel("Lap Number")
ax.set_ylabel("Lap Time")
plt.show()

Error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/opt/anaconda3/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

~/opt/anaconda3/lib/python3.8/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
    246 
    247     if 'png' in formats:
--> 248         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    249     if 'retina' in formats or 'png2x' in formats:
    250         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

~/opt/anaconda3/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    130         FigureCanvasBase(fig)
    131 
--> 132     fig.canvas.print_figure(bytes_io, **kw)
    133     data = bytes_io.getvalue()
    134     if fmt == 'svg':

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2191                            else suppress())
   2192                     with ctx:
-> 2193                         self.figure.draw(renderer)
   2194 
   2195                     bbox_inches = self.figure.get_tightbbox(

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/figure.py in draw(self, renderer)
   1861 
   1862             self.patch.draw(renderer)
-> 1863             mimage._draw_list_compositing_images(
   1864                 renderer, self, artists, self.suppressComposite)
   1865 

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    129     if not_composite or not has_images:
    130         for a in artists:
--> 131             a.draw(renderer)
    132     else:
    133         # Composite any adjacent images together

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py in wrapper(*inner_args, **inner_kwargs)
    409                          else deprecation_addendum,
    410                 **kwargs)
--> 411         return func(*inner_args, **inner_kwargs)
    412 
    413     return wrapper

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
   2745             renderer.stop_rasterizing()
   2746 
-> 2747         mimage._draw_list_compositing_images(renderer, self, artists)
   2748 
   2749         renderer.close_group('axes')

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    129     if not_composite or not has_images:
    130         for a in artists:
--> 131             a.draw(renderer)
    132     else:
    133         # Composite any adjacent images together

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)
   1162         renderer.open_group(__name__, gid=self.get_gid())
   1163 
-> 1164         ticks_to_draw = self._update_ticks()
   1165         ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
   1166                                                                 renderer)

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py in _update_ticks(self)
   1021         major_locs = self.get_majorticklocs()
   1022         major_labels = self.major.formatter.format_ticks(major_locs)
-> 1023         major_ticks = self.get_major_ticks(len(major_locs))
   1024         self.major.formatter.set_locs(major_locs)
   1025         for tick, loc, label in zip(major_ticks, major_locs, major_labels):

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py in get_major_ticks(self, numticks)
   1380         while len(self.majorTicks) < numticks:
   1381             # Update the new tick label properties from the old.
-> 1382             tick = self._get_tick(major=True)
   1383             self.majorTicks.append(tick)
   1384             tick.gridline.set_visible(self._gridOnMajor)

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py in _get_tick(self, major)
   2011         else:
   2012             tick_kw = self._minor_tick_kw
-> 2013         return XTick(self.axes, 0, major=major, **tick_kw)
   2014 
   2015     def set_label_position(self, position):

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py in __init__(self, *args, **kwargs)
    415 
    416     def __init__(self, *args, **kwargs):
--> 417         super().__init__(*args, **kwargs)
    418         # x in data coords, y in axes coords
    419         self.tick1line.set(

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py in wrapper(*inner_args, **inner_kwargs)
    409                          else deprecation_addendum,
    410                 **kwargs)
--> 411         return func(*inner_args, **inner_kwargs)
    412 
    413     return wrapper

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axis.py in __init__(self, axes, loc, label, size, width, color, tickdir, pad, labelsize, labelcolor, zorder, gridOn, tick1On, tick2On, label1On, label2On, major, labelrotation, grid_color, grid_linestyle, grid_linewidth, grid_alpha, **kw)
    157             markeredgecolor=color, markersize=size, markeredgewidth=width,
    158         )
--> 159         self.gridline = mlines.Line2D(
    160             [], [],
    161             color=grid_color, alpha=grid_alpha, visible=gridOn,

TypeError: type object got multiple values for keyword argument 'visible'

<Figure size 432x288 with 1 Axes>
theOehrly commented 2 years ago

Can you please tell me the version of python and matplotlib that you are using? Run the following code in your python interpreter:

>>> import fastf1
>>> fastf1.__version__

and

>>> import matplotlib
>>> matplotlib.__version__

Can you also please give me some more info on the python version you are using and your operating system?

karenx8 commented 2 years ago

Can you please tell me the version of python and matplotlib that you are using? Run the following code in your python interpreter:

>>> import fastf1
>>> fastf1.__version__

and

>>> import matplotlib
>>> matplotlib.__version__

Can you also please give me some more info on the python version you are using and your operating system?

Hello so I did run that code as you said and this is what I got back for fast1 version: '2.2.8' and for the matplotlib I got '3.3.2'

theOehrly commented 2 years ago

You are using anaconda on linux, right?

karenx8 commented 2 years ago

No, I am using anaconda on a mac

theOehrly commented 2 years ago

Ahh, ok. I'll see if I can reproduce the problem. I don't have a mac to test on. So, let's hope that's not the cause.

theOehrly commented 2 years ago

@karenx8 so the problem is the version of matplotlib that you are using. If you can update matplotlib, the issue should be gone. Alternatively, you can call plotting.setup_mpl with misc_mpl_mods=False. You won't get the background grid that is shown in the examples then.

I still need to look at this further until I can decide, what a permanet solution for this will be.

theOehrly commented 2 years ago

I've not made a more strict requirement for matplotlib version 3.3.3 or newer. Everything else would result in hacky version dependent ways to work around api changes and regressions in matplotlib.