Advice on how to get started with 2D-plotting ?
cmpython at gmail.com
Wed Sep 7 07:56:10 CEST 2011
> Now, for my work, I would need to learn the basics fast, for a one-time
> quick-n-dirty job.
> This involves a graphic comparison of RFC1918 IP subnets allocation across
> several networks.
> The idea is to draw parallel lines, with segments (subnets) coloured green,
> yellow or red depending on the conflicts between the networks.
> What would be the simplest/fastest way of getting this done ?
> (the graphic parts, the IP stuff I know how to handle)
AFAIK, probably Matplotlib. I'm not sure what
quite to imagine for your plot but below is code
that makes an attempt at (maybe) something like
you are describing, shown here:
There are smarter ways to do this in matplotlib, but
this is pretty quick and dirty. I'm just plotting
lines over-top other lines. The pic I put is the
plot as a .png, which matplotlib makes if you want,
but you can also view it in a frame that matplotlib
generates and then pan/zoom/etc...
from pylab import *
x = [1,2,3,4,5,6,7,8]
y = [2 for num in x]
#plot the parallel lines themselves in green
for num in range(6):
y = [num for item in x]
#plot any conflict sections in red or yellow
#some hard data to give the idea:
x2 = [3,4]
y2 = [2 for num in x2]
x3 = [5,6,7]
y3 = [4 for num in x3]
x4 = [2,3]
y4 = [3 for num in x4]
#plot these three colored parts over the green lines
pos = arange(6)
yticks(pos, ('net1', 'net2', 'net3', 'net4', 'net5', 'net6'))
More information about the Python-list