6

I have installed Matplotlib, and I have created two lists, x and y.

I want the x-axis to have values from 0 to 100 in steps of 10 and the y-axis to have values from 0 to 1 in steps of 0.1. How do I plot this graph?

3 Answers 3

2

There is a very good book:

Sandro Tosi, Matplotlib for Python Developers, Packt Pub., 2009.

Sign up to request clarification or add additional context in comments.

Comments

2

Use xlim and ylim to set the range to be displayed, [0; 100] and [0; 1] in this case. Use xticks and yticks to control the spacing of the ticks, 10 and 0.01 in this case (11 steps for both).

Complete example

import pylab as pl
import numpy as np

# Sample data
X = np.linspace(-5, 105, 2000, endpoint = True)
Cosine, Sine = 0.45 * np.cos(0.2*X) + 0.5, 0.45 * np.sin(0.2*X) + 0.5


# Plot
pl.plot(X, Cosine)
pl.plot(X, Sine)


# Set x and y limits
pl.xlim(0.0, 100.0)
pl.ylim(0.0,   1.0)


# Set ticks for x and y axis
pl.xticks(np.linspace(0.0, 100.0, 11, endpoint = True))
pl.yticks(np.linspace(0.0,   1.0, 11, endpoint = True))


pl.show()

Result

Plot created by Matplotlib

Comments

0

use the arange function to stepwise your intervals for X and Y

X=np.arange(0,110,10)
Y=np.arange(0,1.1,.1)
print(Y)
plt.scatter(X,Y)

Cosine = np.cos(X) + 0.5
plt.plot(X, Cosine)
plt.show()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.