Repository navigation
Closed as not planned
Labels
status: inactiveMarked by the “Stale” Github ActionMarked by the “Stale” Github Action
Description
Description
Using marker kwarg in grid raise a exception
Version used
python 3.11.2, really I found this bug same time ago using 3.9 or so
matplotlib 3.6.3
Although the error names Tkinter, the error is also reproduced with qt backend
Code to reproduce
from matplotlib import pyplot
x = [0, 1]
y = [0, 1]
pyplot.plot(x, y)
pyplot.grid(True, marker="o")
pyplot.show()
And the exception raised...
jjgomera@msi:~/Programacion/pychemqt$ python3 bug.py
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.11/tkinter/__init__.py", line 1948, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/tkinter/__init__.py", line 861, in callit
func(*args)
File "/usr/lib/python3/dist-packages/matplotlib/backends/_backend_tk.py", line 251, in idle_draw
self.draw()
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 10, in draw
super().draw()
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 405, in draw
self.figure.draw(self.renderer)
File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 74, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 51, in draw_wrapper
return draw(artist, renderer)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 3082, in draw
mimage._draw_list_compositing_images(
File "/usr/lib/python3/dist-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 51, in draw_wrapper
return draw(artist, renderer)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 3100, in draw
mimage._draw_list_compositing_images(
File "/usr/lib/python3/dist-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 51, in draw_wrapper
return draw(artist, renderer)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1304, in draw
ticks_to_draw = self._update_ticks()
^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1192, in _update_ticks
major_ticks = self.get_major_ticks(len(major_locs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1534, in get_major_ticks
tick = self._get_tick(major=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1483, in _get_tick
return self._tick_class(self.axes, 0, major=major, **tick_kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 422, in __init__
super().__init__(*args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 166, in __init__
self.gridline = mlines.Line2D(
^^^^^^^^^^^^^^
TypeError: matplotlib.lines.Line2D() got multiple values for keyword argument 'marker'
Metadata
Metadata
Assignees
Labels
status: inactiveMarked by the “Stale” Github ActionMarked by the “Stale” Github Action
Activity
jklymak commentedon May 18, 2023
Did this ever work? What did it do, or do you expect it to do?
ksunden commentedon May 18, 2023
For what its worth, i do find it unlikely that it would actually do what you expect.
Here is what I get if I modify the grid to have markers (just by editing the last line in the traceback to have
marker='o'instead ofmarker='', i.e. not making it so that explicitly passing doesn't error):This seems unlikely to be desirable, I don't think? but it wouldn't be too hard to add handling for marker like we do for other kwargs there... it is also be possible to workaround it by setting the marker after enabling the grid for the first time, though that can still be fragile when continuing to manipulate the plot (i.e. it will still raise later on):
It's not the most elegant, but it works.
If, for instance, you were expecting a lattice of points at each intersection of the grid lines, that is not something that actually fits into the way
gridis implemented, as it is done on the individualaxis(e.g. X axis or Y axis, with no knowledge of where the ticks are )jjgomera commentedon May 18, 2023
Thanks, I just want to allow the user full control of the graphics settings, in the same way that you can set the line or its color. Thanks for the workaround. You are right, the marks do not make much sense in the grid, but I want to point out that in the documentation of grid, marker and its related kwargs should not be included, or if they do the result must be as you show, but no raise exception.
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.grid.html
timhoffm commentedon May 18, 2023
I'm -1 on allowing marker for grid. That doesn't make sense. It should be an implementation detail that these lines are implemented using
Line2D.Correcting the list in https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.grid.html is not easily possible, because it is auto-generated from
Line2D, which is where the implementation leaks out. I don't consider this an important enough problem to invest any effort. If you want to, modify the docs to something likegithub-actions commentedon Jun 29, 2026
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
timhoffm commentedon Jun 29, 2026
Per my comment, I close this without further action.