开发者

python Matplotlib -- Multiple Chart Objects?

How can I use matplotlib to create many different chart objects and then have the ability to control each chart object separately (without affecting the other chart objects)?

Ideally, I'd like to have something of the following:

# creating开发者_JAVA百科 the chart handler object

chartHandler = ChartHandler()

# plotting some values for chart #0

chartHandler[0].plot( range(0,100) )

# plotting some values for chart #5

chartHandler[5].plot( range(500,700) )


Unless you are talking about something that I haven't dealt with in matplotlib yet, I think that what you are looking for is figure.add_subplot(). You should be able to capture the return from each figure.add_subplot() and operate on each individually from then on, kind of like this:

import matplotlib.pyplot as plt

#Create an 11x5 figure
fig = plt.figure(figsize=(11,5))

#Create subplots[0]
subplts = []
subplt = fig.add_subplot(121)
subplts.append(subplt)

#Create subplots[1:20]
for xind in range(4,8):
    for yind in range(0,5):
        subplt = fig.add_subplot(5,8,(yind*8+xind))
        subplts.append(subplt)

plt.show()

It should be noted that there are a few problems with the above script. Mainly, the subplots overlap slightly. This can be solved using the position keyword to add_subplot and some simple math.

In any case, you can now modify each subplot by referencing its index in subplots. It should be pretty simple to add plots, modify ranges, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜