Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Using Axis.grid(visible=True) results in TypeError for multiple values for keyword argument #18758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Electro707 opened this issue Oct 17, 2020 · 0 comments · Fixed by #18769
Closed
Milestone

Comments

@Electro707
Copy link

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 the visible argument with the value gridOn. When visible is fed into Axis.grid(), it looks like there is no check for that, and thus it feeds mlines.Line2D() with the visible argument in grid_kw even though visible is already seperatly set.

Code for reproduction

import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure

root = 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
@QuLogic QuLogic added this to the v3.3.3 milestone Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants