1

I am learning matplolib. I try do display specific point on a surface and I get the following result :

We can hardly see the point here Here we can't

Both screenshot comes from the same figure. On the first one, we can hardly see the point I want to display, not on the second. I would like to make it appears on each. Here is my code :

import numpy as np
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

hours, pauses, results = [], [], []

with open('./data.txt', 'r') as f:
    for line in f:
        value = line.split()
        for i, l in enumerate([hours, pauses, results]):
            l.append(int(value[i]))

for l in [hours, pauses, results]:
    l = np.asarray(l, dtype=float)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

m = len(hours)

WP_init = 5 * np.random.rand()
WH_init = 5 * np.random.rand()
Z_init = 0
for i in range(m):
    Z_init += 1. / (2 * m) * (WH_init * hours[i] + WP_init * pauses[i] - results[i])**2
ax.scatter(WH_init, WP_init, Z_init, s=40, c='r', marker='o')


WH = np.arange(-5, 5, 0.25)
WP = np.arange(-5, 5, 0.25)
WH, WP = np.meshgrid(WH, WP)
Z = np.zeros(np.shape(WP))
for i in range(m):
    Z += 1. / (2 * m) * (WH * hours[i] + WP * pauses[i] - results[i])**2

ax.plot_surface(WH, WP, Z, rstride=4, cstride=4, cmap=cm.coolwarm)

plt.show()

Do you know how I could fix these ?

Thanks

edit : here is the content of data.txt :
12 0 13
12 8 18
10 0 14
10 4 16
8 0 14
8 2 15
8 8 8
6 0 13
6 3 11
4 0 8
4 4 4
2 2 2
0 0 0

1 Answer 1

5

You could set the alpha of the surface to something less than 1 so that its opaqueness can not totally obscure the red dot:

ax.plot_surface(WH, WP, Z, rstride=4, cstride=4, cmap=cm.coolwarm, alpha=0.5)

enter image description here

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.