Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'matplotlib.pyplot' has no attribute 'axline'

I have a problem :

Here is the documentation : https://matplotlib.org/stable/gallery/pyplots/axline.html#sphx-glr-gallery-pyplots-axline-py

Here is my code

import matplotlib.pyplot as plt
import numpy as np

for pos in np.linspace(-2, 1, 10):
    plt.axline((pos, 0), slope=0.5, color='k', transform=plt.gca().transAxes)

plt.ylim([0, 1])
plt.xlim([0, 1])
plt.show()

Here is the terminal :

Traceback (most recent call last):
  File "/home/toto/path/of/the/project/testsubplot.py", line 7, in <module>
    plt.axline((pos, 0), slope=0.5, color='k', transform=plt.gca().transAxes)
AttributeError: module 'matplotlib.pyplot' has no attribute 'axline'

I am on Ubuntu 20.1 and I have matplotlib-3.5.1.

Why do I have this error ? I really don't understand why I have AttributeError: module 'matplotlib.pyplot' has no attribute 'axline'. In fact It has the attribute, so why do I have this error ? And how can I fix it ?

like image 724
Student_in_computer_science Avatar asked Oct 28 '25 07:10

Student_in_computer_science


1 Answers

!pip install matplotlib --upgrade in google colab this works for me

like image 129
AdriQu3 Avatar answered Oct 31 '25 11:10

AdriQu3