Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12846 > unrolled thread
| Started by | Fred Pacquier <xnews2@fredp.lautre.net> |
|---|---|
| First post | 2011-09-06 18:27 +0000 |
| Last post | 2011-09-07 18:24 +0000 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.python
Advice on how to get started with 2D-plotting ? Fred Pacquier <xnews2@fredp.lautre.net> - 2011-09-06 18:27 +0000
Re: Advice on how to get started with 2D-plotting ? rantingrick <rantingrick@gmail.com> - 2011-09-06 13:59 -0700
Re: Advice on how to get started with 2D-plotting ? CM <cmpython@gmail.com> - 2011-09-06 23:00 -0700
Re: Advice on how to get started with 2D-plotting ? CM <cmpython@gmail.com> - 2011-09-06 22:56 -0700
Re: Advice on how to get started with 2D-plotting ? Weinhandl Herbert <herbert.weinhandl@oeaw.ac.at> - 2011-09-07 09:14 +0200
Re: Advice on how to get started with 2D-plotting ? Fred Pacquier <xnews2@fredp.lautre.net> - 2011-09-07 18:24 +0000
| From | Fred Pacquier <xnews2@fredp.lautre.net> |
|---|---|
| Date | 2011-09-06 18:27 +0000 |
| Subject | Advice on how to get started with 2D-plotting ? |
| Message-ID | <Xns9F58D020011D0PaCmAnRDLM@212.27.60.38> |
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
[toc] | [next] | [standalone]
| From | rantingrick <rantingrick@gmail.com> |
|---|---|
| Date | 2011-09-06 13:59 -0700 |
| Message-ID | <27d7b2a8-1a24-4066-b603-13c935c42af1@fd21g2000vbb.googlegroups.com> |
| In reply to | #12846 |
On Sep 6, 1:27 pm, Fred Pacquier <xne...@fredp.lautre.net> wrote:
> 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?
[toc] | [prev] | [next] | [standalone]
| From | CM <cmpython@gmail.com> |
|---|---|
| Date | 2011-09-06 23:00 -0700 |
| Message-ID | <ee54313f-9875-4029-9ae0-02e807c1adf9@fe21g2000vbb.googlegroups.com> |
| In reply to | #12846 |
On Sep 6, 2:27 pm, Fred Pacquier <xne...@fredp.lautre.net> wrote:
> 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
[toc] | [prev] | [next] | [standalone]
| From | CM <cmpython@gmail.com> |
|---|---|
| Date | 2011-09-06 22:56 -0700 |
| Message-ID | <d0497b85-3c1f-41c9-92bf-788562815712@z18g2000yqb.googlegroups.com> |
| In reply to | #12846 |
> 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
[toc] | [prev] | [next] | [standalone]
| From | Weinhandl Herbert <herbert.weinhandl@oeaw.ac.at> |
|---|---|
| Date | 2011-09-07 09:14 +0200 |
| Message-ID | <4e6719f1$0$38260$3b214f66@aconews.univie.ac.at> |
| In reply to | #12846 |
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
[toc] | [prev] | [next] | [standalone]
| From | Fred Pacquier <xnews2@fredp.lautre.net> |
|---|---|
| Date | 2011-09-07 18:24 +0000 |
| Message-ID | <Xns9F59CF99ADCBFPaCmAnRDLM@212.27.60.39> |
| In reply to | #12882 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web