Plotting y=x^2 with Matplotlib

In summary, the conversation discusses the use of the matplotlib.pyplot library and its function to plot a graph using a specific range and mathematical operation. The topic of using a line code or keyword argument is also mentioned. The conversation also refers to additional resources for more information on the topic.
  • #1
joseph2015
14
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
plotting:
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()
 
Technology news on Phys.org
  • #4
how about using ls='--' or linestyle='--' ie a keyword argument?
 
  • #5
I think you want
Code:
plt.plot(x,y,'-')
 
  • #6
plt.plot(x,y), no need to put a linestyle into the argument...
 
  • #7
Thank you very much for your replies and helps
 

1. What is Matplotlib?

Matplotlib is a Python library used for creating high-quality visualizations such as graphs, charts, and plots. It provides a wide range of customizable features to create professional-looking plots.

2. How do I plot y=x^2 with Matplotlib?

To plot y=x^2 with Matplotlib, you first need to import the library and create two arrays containing the x and y values. Then, you can use the plt.plot() function to plot the data and use plt.show() to display the plot.

3. Can I customize the appearance of the plot?

Yes, you can customize the appearance of your plot in various ways using Matplotlib. You can change the color, style, and size of the plot, add labels and titles, and even add multiple plots on the same figure.

4. How can I save my plot as an image?

To save your plot as an image, you can use the plt.savefig() function. This will save the plot in the specified file format, such as PNG or JPG. You can also specify the resolution and quality of the image.

5. Is Matplotlib only limited to 2D plots?

No, Matplotlib can also create 3D plots using the mpl_toolkits.mplot3d module. This allows you to plot data in three dimensions, adding depth and perspective to your visualizations.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
1
Views
587
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
9K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
21
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
Back
Top