How to Plot y=x^2 Using Matplotlib?

  • Context: Python 
  • Thread starter Thread starter joseph2015
  • Start date Start date
  • Tags Tags
    Matplotlib Plotting
Click For Summary

Discussion Overview

The discussion revolves around plotting the function y=x^2 using Matplotlib, focusing on the correct syntax and options for visual representation. It includes technical explanations and suggestions for improving the plot's appearance.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant provides a code snippet for plotting y=x^2 but comments out the line that would plot points, opting for a dashed line style instead.
  • Another participant suggests checking the Matplotlib documentation for guidance on plotting.
  • A subsequent reply acknowledges the documentation but notes that the current code will produce points despite using a line style.
  • Another participant proposes using the keyword argument ls='--' or linestyle='--' to specify the line style more clearly.
  • One participant suggests simply using plt.plot(x,y,'-') for a solid line.
  • Another participant states that plt.plot(x,y) is sufficient without specifying a linestyle.
  • A later reply expresses gratitude for the assistance received in the discussion.

Areas of Agreement / Disagreement

Participants present multiple competing views on the best way to specify line styles in the plot, and there is no consensus on a single correct approach.

Contextual Notes

Some responses may depend on the specific version of Matplotlib being used, and there are unresolved questions about the output of the initial code snippet.

joseph2015
Messages
14
Reaction score
2
TL;DR
Hello all
I would like to plot my outcome with lines. So line 7 workes but it produces markers such as (o or ^). My question is how to make line 8 works to plot lines instead of discrete points?
Thanks in advance

Joe
[CODE lang="python" title="plotting" highlight="7,8"]import matplotlib.pyplot as plt

R = 2

for x in range(0,50):
y = x**R
# plt.plot(x,y,marker = 'o')
plt.plot(x,y,'--')

plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('plot test')
plt.legend()
plt.show()[/CODE]
 
Technology news on Phys.org
how about using ls='--' or linestyle='--' ie a keyword argument?
 
I think you want
Code:
plt.plot(x,y,'-')
 
plt.plot(x,y), no need to put a linestyle into the argument...
 
Thank you very much for your replies and helps
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
4
Views
5K
  • · Replies 21 ·
Replies
21
Views
6K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K