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
SUMMARY

This discussion focuses on plotting the function y=x² using Matplotlib version 3.3.3. The user initially attempted to plot the function with a dashed line style using the syntax plt.plot(x,y,'--'). A suggestion was made to utilize keyword arguments such as ls='--' or linestyle='--' for better clarity. The consensus is that using plt.plot(x,y) without additional arguments is sufficient for a solid line plot.

PREREQUISITES
  • Familiarity with Python programming
  • Understanding of basic plotting concepts
  • Knowledge of Matplotlib library functions
  • Basic algebra, specifically quadratic functions
NEXT STEPS
  • Explore advanced Matplotlib features such as subplots and 3D plotting
  • Learn about customizing plot aesthetics in Matplotlib
  • Investigate the use of NumPy for efficient mathematical operations
  • Study the Matplotlib documentation for additional plotting functions
USEFUL FOR

Data scientists, Python developers, and anyone interested in visualizing mathematical functions using Matplotlib.

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
962
  • · Replies 2 ·
Replies
2
Views
1K
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