Advice on how to get started with 2D-plotting ?

F

Fred Pacquier

Hi,

I'm a Python long-timer, but I've never had to use tools like Matplotlib &
others before.

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)

Alternately, if someone knows of a ready-made and accessible tool that does
just that, I'm all ears :)

TIA,
fp
 
R

rantingrick

I'm a Python long-timer, but I've never had to use tools like Matplotlib &
others before.

Now, for my work, I would need to learn the basics fast, for a one-time
quick-n-dirty job.

##################
## START SCRIPT ##
##################
#
# Easy_as.py
#
import Tkinter as tk
# Create a main window and a canvas.
app = tk.Tk()
can = tk.Canvas(
app,
width=500,
height=500,
#bd=1,
#relief=tk.SOLID,
)
can.pack(
fill=tk.BOTH,
expand=True,
padx=5,
pady=5,
)
# Create some gridlines on the canvas.
W,H = 500, 500
row, col = 0,0
for _ in range(10):
can.create_line(0, row, W, row, fill='red')
print 0, row, W, row
can.create_line(col, 0, col, H, fill='green')
row += 50
col += 50
can.create_line(
0,500,300,300,
350,200,400,450,
fill='magenta',
width=5,
)
# Start the event loop.
app.mainloop()
################
## END SCRIPT ##
################

Any questions?
 
C

CM

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:

http://www.flickr.com/photos/67254913@N07/6123112552/in/photostream#/

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(x,y,color='g',lw='4')

#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
plot(x2,y2,color='r',lw='12')
plot(x3,y3,color='yellow',lw='12')
plot(x4,y4,color='r',lw='12')

pos = arange(6)
yticks(pos, ('net1', 'net2', 'net3', 'net4', 'net5', 'net6'))

show()

#-------------------------

Che
 
C

CM

Hi,

I'm a Python long-timer, but I've never had to use tools like Matplotlib &
others before.

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)

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)

One fairly simple way is with Matplotlib. 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:

http://www.flickr.com/photos/67254913@N07/6123112552/in/photostream#/

There are fancier 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... This is using the
pylab module, but you could also embed your plots in
a GUI if you prefer.


from pylab import *

#plot the parallel lines in green
x = [1,2,3,4,5,6,7,8]
y = [2 for num in x]
for num in range(6):
y = [num for item in x]
plot(x,y,color='g',lw='4')

#plot any conflict sections in red or yellow
#...some 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 three colored parts over the green lines
plot(x2,y2,color='r',lw='12')
plot(x3,y3,color='yellow',lw='12')
plot(x4,y4,color='r',lw='12')

#change y labels to meaningful labels
pos = arange(6)
yticks(pos, ('net1', 'net2', 'net3', 'net4', 'net5', 'net6'))

show()

#-------------------------

Che
 
W

Weinhandl Herbert

Am 06.09.2011 20:27, schrieb Fred Pacquier:
Hi,

I'm a Python long-timer, but I've never had to use tools like Matplotlib&
others before.

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.

maybe networkx
http://pypi.python.org/pypi/networkx/1.5
http://networkx.lanl.gov/
is a better solution for your problem
or
http://pypi.python.org/pypi/graphcanvas/4.0.0
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)

Alternately, if someone knows of a ready-made and accessible tool that does
just that, I'm all ears :)

TIA,
fp

hth

Herbert
 
F

Fred Pacquier

Wow, what an impressive turnout !

Thanks a lot, rantingrick, CM and Herbert, for the fast answers, useful
tips and especially the sample code !

Beats starting from a blank page, with a big stick, and will certainly set
me on my way much faster...

networkx does seem a bit over the top for my simple goal, but both the Tk
(I always forget Tk !) and Matplotlib approaches seem to fit the KISS
principle just fine... on to the tinkering now :)

Again, thanks to all !
fp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,127
Latest member
CyberDefense
Top