Matplotlib Line3DCollection multicolored line edges are "jagged"
<p>Based on the <a href="http://matplotlib.org/examples/pylab_examples/multicolored_line.html" rel="noreferrer">matplotlib example code</a> I constructed a 3D version of a multicolored line. I am working in a jupyter notebook and by using <code>%matplotlib notebook</code> I may zoom into the plot and the corner edges are rendered smoothly in my browser - perfect! However, when I export the plot as png or pdf file for further usage the corner edges are "jagged".</p>

<p>Any ideas how to smoothen the 3D-multicolored line?</p>

<p><a href="https://i.stack.imgur.com/XLAwG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XLAwG.png" alt="edges 3D png-file"></a></p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap, BoundaryNorm    
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Line3DCollection
%matplotlib notebook

# Generate random data
np.random.seed(1)
n = 20 # number of data points
#set x,y,z data
x = np.random.uniform(0, 1, n)
y  = np.random.uniform(0, 1, n)
z = np.arange(0,n)

# Create a colormap for red, green and blue and a norm to color
# f' &lt; -0.5 red, f' &gt; 0.5 blue, and the rest green
cmap = ListedColormap(['r', 'g', 'b'])
norm = BoundaryNorm([-1, -0.5, 0.5, 1], cmap.N)

#################
### 3D Figure ###
#################

# Create a set of line segments
points = np.array([x, y, z]).T.reshape(-1, 1, 3)
segments = np.concatenate([points[:-1], points[1:]], axis=1)

# Create the 3D-line collection object
lc = Line3DCollection(segments, cmap=plt.get_cmap('copper'),
                    norm=plt.Normalize(0, n))
lc.set_array(z) 
lc.set_linewidth(2)

#plot
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_zlim(0, max(z))
plt.title('3D-Figure')
ax.add_collection3d(lc, zs=z, zdir='z')

#save plot
plt.savefig('3D_Line.png', dpi=600, facecolor='w', edgecolor='w',
            orientation='portrait')
</code></pre>