Exemple de comment tracer avec matplotlib un graphique de coordonnées parallèles:

#!/usr/bin/pythonimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.ticker as ticker#vectors to plot: 4D for this exampley1=[1,2.3,8.0,2.5]y2=[7.5,6.2,2.2,3.9]x=[1,2,3,8] # spinesfig,(ax,ax2,ax3) = plt.subplots(1, 3, sharey=False)# plot the same on all the subplotsax.plot(x,y1,'r-', x,y2,'b-')ax2.plot(x,y1,'r-', x,y2,'b-')ax3.plot(x,y1,'r-', x,y2,'b-')# now zoom in each of the subplotsax.set_xlim([ x[0],x[1]])ax2.set_xlim([ x[1],x[2]])ax3.set_xlim([ x[2],x[3]])# set the x axis ticksfor axx,xx in zip([ax,ax2,ax3],x[:-1]):axx.xaxis.set_major_locator(ticker.FixedLocator([xx]))ax3.xaxis.set_major_locator(ticker.FixedLocator([x[-2],x[-1]])) # the last one# EDIT: add the labels to the rightmost spinefor tick in ax3.yaxis.get_major_ticks():tick.label2On=True# Remove Top and Bottom Axis Linesfor axx in [ax,ax2,ax3]:axx.spines['top'].set_visible(False)axx.spines['bottom'].set_visible(False)# Change parallel lines Widthlw = 1.5ax.spines['left'].set_linewidth(lw)ax2.spines['left'].set_linewidth(lw)ax3.spines['left'].set_linewidth(lw)ax3.spines['right'].set_linewidth(lw)# stack the subplots togetherplt.subplots_adjust(wspace=0)plt.savefig("ParallelCoordinatesMatplotlib.png")plt.show()
Recherches associées
| Liens | Site |
|---|---|
| Parallel Coordinates plot in Matplotlib | stackoverflow |
| Coordonnées parallèles | wikipedia |
| Parallel coordinates | wikipedia |
| pylab_examples example code: spine_placement_demo.py | matplotlib doc |
Setting axes.linewidth without changing the rcParams global dict |
stackoverflow |
| How to display only a left and bottom box border in matplotlib? | stackoverflow |
