SaiyanGirl - 3 years ago 283

Python Question

My data is the following:

`x = [3,4,5,6,7,8,9,9]`

y = [6,5,4,3,2,1,1,2]

And I can obtain the following two graphs.

and

However, what I want is

Is it possible in matplotlib? Or do I have to change the list manually and somehow create:

`x = [3,4,5,6,7,8,9]`

y = [6,5,4,3,2,1,1.5]

`ax.plot(x, y, 'o-', label='curPerform')`

x1,x2,y1,y2 = ax.axis()

x1 = min(x) - 1

x2 = max(x) + 1

ax.axis((x1,x2,(y1-1),(y2+1)))

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Yes, you must do the calculation yourself. `plot`

plots the data you give it. If you want to plot some other data, you need to calculate that data yourself and then plot that instead.

Edit: A quick way to do the calculation:

```
>>> x, y = zip(*sorted((xVal, np.mean([yVal for a, yVal in zip(x, y) if xVal==a])) for xVal in set(x)))
>>> x
(3, 4, 5, 6, 7, 8, 9)
>>> y
(6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 1.5)
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**