Home > OS >  Full graph without calculating all points, possible?
Full graph without calculating all points, possible?

Time:04-10

I would like to draw a graph with predefined values from 0 to 605 for example. My pc is not powerful enough to calculate everything so I would like to calculate only some points and connect them all to have a curve on the interval [0;605]. How can I do this? Is this possible? I tried to put a step, but it automatically reduces the interval.

In my current code it only shows me 605/10 values = 60, so the range of the graph is from 0 to 60 for the x-axis.

tab=[]

for k in range(1,605,10): 

    img2 = rgb(k)

    d = psnr(img1,img2)

    tab.append(d)

plt.plot(tab)
plt.xlabel("k")
plt.ylabel("PSNR")
plt.show()

CodePudding user response:

You can set the xticks by yourself: plt.xticks(x_values, [0, 10, 20, 30, ...])

CodePudding user response:

You need to plot with the pattern plt.plot(x, y) instead of only plt.plot(y).

A quick fix (just to show the idea) can be:

  1. Create an empty x, just like tab: x = []
  2. Append k to x in the loop: x.append(k)
  3. Do plt.plot(x, tab), instead of plt.plot(tab)
  • Related