Python Forum
plt.style() in matplotlib causes error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plt.style() in matplotlib causes error
#1
I'm doing some of the projects from Python Crash Course 2nd Ed., as I'm new to the language.

A simple point plotter throws an error when plt.style() is called. Here's the code:

import matplotlib.pyplot as plt

input_values = [1, 2, 3, 4, 5]
squares = [1, 4, 9, 16, 25]

'''''''The error is here'''''''''''''''
plt.style.use('seaborn')
'''''''''''''''''''''''''''''''''''''''
fig, ax = plt.subplots()
ax.plot(input_values, squares, linewidth=3)

# Set chart title and label axes.
ax.set_title("Square Numbers", fontsize=24)
ax.set_xlabel("Value", fontsize=14)
ax.set_ylabel("Square of Value", fontsize=14)

# Set size of tick labels.
ax.tick_params(axis='both', labelsize=14)

plt.show()
When I run from my text editor, I get the following error:
Traceback (most recent call last):
  File "/Users/leecreighton/Desktop/ehmatthes-pcc_2e-d6b34cf/chapter_15/plotting_simple_line_graph/mpl_squares.py", line 6, in <module>
    plt.style.use('seaborn')
AttributeError: 'module' object has no attribute 'style'
I have tried doing a clean uninstall and reinstall of anaconda, and I have tried installing matplotlib using pip, and I still get this error. I'm quite disheartened.
Reply
#2
What version of matplotlib is installed on your computer, matplotlib.__version__?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] plt.style() in matplotlib causes error olufaruqu 4 1,117 May-12-2023, 01:41 PM
Last Post: olufaruqu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020