2

I am using matplotlib and I am struggling with style attributes. How to add a marker only to the start point or end point of a 3D line and not on both sides?

user7924113
  • 169
  • 1
  • 3
  • 15
  • 2
    You could use a single-point scatter plot – Andrew Apr 22 '20 at 14:52
  • Possible duplicate: [How to mark specific data points in matplotlib graph](https://stackoverflow.com/questions/47211866/how-to-mark-specific-data-points-in-matplotlib-graph) - using `[0]` or `[-1]` for the `markevery` argument. – wwii Apr 22 '20 at 15:56

1 Answers1

4

Use the markevery parameter when plotting.

Example from the Parametric Curve example in the Gallery (version 2.2.5).

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

plt.rcParams['legend.fontsize'] = 10

fig = plt.figure()
ax = fig.gca(projection='3d')

# Prepare arrays x, y, z
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)

l = ax.plot(x, y, z, marker='o', label='parametric curve both ends', markevery=[0,-1])
l = ax.plot(x+1, y+1, z, 'r', marker='o', label='parametric curve one end', markevery=[0])
ax.legend()

plt.show()
plt.close()

I used the example from version 2.2.5 because I don't have 3.2 installed. Making a 3d axis changed in 3.something - 3.2 example link.


Axes.plot markevery parameter

wwii
  • 23,232
  • 7
  • 37
  • 77