Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug report
Bug summary
If Axis.grid(visible=True) is used instead of Axis.grid(), it will generate a TypeError. The same goes for if Axis.grid(visible=False).
This is due to the Tick class's (axis.py) init function, where in line 159 it creates the gridlines with mlines.Line2D(), where it feeds it thevisible argument with the value gridOn. Whenvisible is fed into Axis.grid(), it looks like there is no check for that, and thus it feeds mlines.Line2D() with thevisible argument in grid_kw even thoughvisible is already seperatly set.
Code for reproduction
importtkinterastkfrommatplotlib.backends.backend_tkaggimportFigureCanvasTkAggfrommatplotlib.figureimportFigureroot=tk.Tk()root.title("Matplotlib Bug Test")fig=Figure(figsize=[8,5])ax=fig.add_subplot(1,1,1)ax.grid(visible=True)ax.set_autoscaley_on(True)ln=ax.plot([],color='black',linewidth=2)[0]canvas=FigureCanvasTkAgg(fig,master=root)canvas.draw()canvas.get_tk_widget().pack()root.mainloop()
Actual outcome
Traceback (most recent call last): File "/run/media/electro/ELECTRO/Work_SMD/Local_Copy/903-8318 - Mini Deltec Test Software/Matplotlib Bug/main2.py", line 15, in <module> canvas.draw() File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/backends/backend_tkagg.py", line 9, in draw super(FigureCanvasTkAgg, self).draw() File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py", line 407, in draw self.figure.draw(self.renderer) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper return draw(artist, renderer, *args, **kwargs) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/figure.py", line 1863, in draw mimage._draw_list_compositing_images( File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images a.draw(renderer) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper return draw(artist, renderer, *args, **kwargs) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py", line 411, in wrapper return func(*inner_args, **inner_kwargs) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 2747, in draw mimage._draw_list_compositing_images(renderer, self, artists) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images a.draw(renderer) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 41, in draw_wrapper return draw(artist, renderer, *args, **kwargs) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/axis.py", line 1164, in draw ticks_to_draw = self._update_ticks() File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/axis.py", line 1023, in _update_ticks major_ticks = self.get_major_ticks(len(major_locs)) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/axis.py", line 1382, in get_major_ticks tick = self._get_tick(major=True) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/axis.py", line 2013, in _get_tick return XTick(self.axes, 0, major=major, **tick_kw) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/axis.py", line 417, in __init__ super().__init__(*args, **kwargs) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py", line 411, in wrapper return func(*inner_args, **inner_kwargs) File "/home/electro/.local/lib/python3.8/site-packages/matplotlib/axis.py", line 159, in __init__ self.gridline = mlines.Line2D(TypeError: type object got multiple values for keyword argument 'visible'
Expected outcome
As the keyword visible is to change the grid's Line2D properties, Axis.grid(True) and Axis.grid(visible=True) should have the same outcome. Either that or it should noted in the Axis.grid documentation to not use the visible kwargs. I personally think it should be the former.
Matplotlib version
- Operating system: Arch Linux
- Matplotlib version: 3.3.2
- Matplotlib backend (
print(matplotlib.get_backend())
): matplotlib - Python version: 3.8
- Jupyter version (if applicable):
- Other libraries:
- Installation Method: pip3