Python How to Plot y=x^2 Using Matplotlib?

AI Thread Summary
The discussion focuses on using Matplotlib for plotting in Python. A user shares code to plot a graph of y = x^R with R set to 2, initially using a dashed line style. There is clarification on how to control the line style, suggesting the use of keyword arguments like ls='--' or linestyle='--' for better customization. The conversation emphasizes that using plt.plot(x, y) without additional arguments defaults to a solid line, which may be more straightforward for users. The importance of understanding line styles in Matplotlib is highlighted, along with references to the official documentation for further guidance.
joseph2015
Messages
14
Reaction score
2
TL;DR Summary
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
Views
7K
Replies
2
Views
1K
Replies
21
Views
5K
Replies
1
Views
11K
Replies
9
Views
3K
Replies
1
Views
2K
Replies
1
Views
1K
Back
Top