Skip to content

Conversation

@ShekharBhardwaj
Copy link

@ShekharBhardwaj ShekharBhardwaj commented Jan 2, 2026

The code was using 6 values (-6, 6, -6, 6, -6, 6) for plt.axis(), which is only valid for 3D plots (x, y, z).
Since this is a 2D plot, it needs only 4 values:
xmin, xmax, ymin, ymax
Changed it to plt.axis((-6, 6, -6, 6)) — sets the x-axis from -6 to 6 and the y-axis from -6 to 6. The code should run without errors now.

fixing this issue


TypeError Traceback (most recent call last)
Cell In[9], line 15
13 plt.legend()
14 plt.axis('square')
---> 15 plt.axis((-6, 6, -6, 6, -6, 6 ))
16 plt.grid()
17 plt.show()

File /opt/anaconda3/lib/python3.13/site-packages/matplotlib/pyplot.py:2940, in axis(arg, emit, **kwargs)
2932 @_copy_docstring_and_deprecators(Axes.axis)
2933 def axis(
2934 arg: tuple[float, float, float, float] | bool | str | None = None,
(...)
2938 **kwargs,
2939 ) -> tuple[float, float, float, float]:
-> 2940 return gca().axis(arg, emit=emit, **kwargs)

File /opt/anaconda3/lib/python3.13/site-packages/matplotlib/axes/_base.py:2174, in _AxesBase.axis(self, arg, emit, **kwargs)
2172 if arg is not None:
2173 if len(arg) != 2len(self._axis_names):
-> 2174 raise TypeError(
2175 "The first argument to axis() must be an iterable of the form "
2176 "[{}]".format(", ".join(
2177 f"{name}min, {name}max" for name in self._axis_names)))
2178 limits = {
2179 name: arg[2
i:2*(i+1)]
2180 for i, name in enumerate(self._axis_names)
2181 }
2182 else:

TypeError: The first argument to axis() must be an iterable of the form [xmin, xmax, ymin, ymax]

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 this pull request may close these issues.

1 participant