Exemple de comment tracer avec matplotlib un graphique de coordonnées parallèles:
#!/usr/bin/python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
#vectors to plot: 4D for this example
y1=[1,2.3,8.0,2.5]
y2=[7.5,6.2,2.2,3.9]
x=[1,2,3,8] # spines
fig,(ax,ax2,ax3) = plt.subplots(1, 3, sharey=False)
# plot the same on all the subplots
ax.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 subplots
ax.set_xlim([ x[0],x[1]])
ax2.set_xlim([ x[1],x[2]])
ax3.set_xlim([ x[2],x[3]])
# set the x axis ticks
for 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 spine
for tick in ax3.yaxis.get_major_ticks():
tick.label2On=True
# Remove Top and Bottom Axis Lines
for axx in [ax,ax2,ax3]:
axx.spines['top'].set_visible(False)
axx.spines['bottom'].set_visible(False)
# Change parallel lines Width
lw = 1.5
ax.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 together
plt.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 |