hanugm
hanugm

Reputation: 1417

How to plot my data using MatPloitLib with step size

Consider the following code and the graph obtained from it

import matplotlib.pyplot as plt
import numpy as np
fig,axs = plt.subplots(figsize=(10,10)) 
data1 = [5, 6, 18, 7, 19]
x_ax = [10, 20, 30, 40, 50]
y_ax = [0, 5, 10, 15, 20]
axs.plot(data1,marker="o")
axs.set_xticks(x_ax)
axs.set_xticklabels(labels=x_ax,rotation=45)
axs.set_yticks(y_ax)
axs.set_yticklabels(labels=y_ax,rotation=45)
axs.set_xlabel("X")
axs.set_ylabel("Y")
axs.set_title("Name")

Graph for the code

I need to plot my data1 = [5, 6, 18, 7, 19] with a step size of 10. 5 for 10, 6 for 20, 18 for 30, 7 for 40 and 19 for 50. But the plot is taking a step size of one.

How can I modify my code to do the required?

Upvotes: 0

Views: 158

Answers (1)

Stef
Stef

Reputation: 30639

If you don't provide x values to plot, it'll automatically use 0, 1, 2 ....

So in your case you need:

x = range(10, len(data1)*10+1, 10)
axs.plot(x, data1, marker="o")

enter image description here

Upvotes: 2

Related Questions