-2

I will not be able to put the code here because it is my assignment.

My program is printing multiple graphs on one plot. Please look at the example figure on the following link: Python: Plot multiple graphs on the same figure

The link above is just an example. That is not my code nor do I have the same program. My topic is completely different. That figure is just for reference.

The line of code I am using to achieve this is: plot(a,b, label=str(meters)) What I want to do is get any one of those graph from those three curves and also plot it separately as if it is the main graph. I am doing all this inside a function, and I have created an array of numbers to loop through these different values to get three different graphs.

Community
  • 1
  • 1
krazzy
  • 179
  • 1
  • 1
  • 10
  • Can you specify what you mean by "and also plot it separately as if it is the main graph". "As if"? Do you want to plot one of the lines in a different axes? Have you checked out the [matplotlib examples](http://matplotlib.org/gallery.html)? – Oliver W. Oct 27 '14 at 22:19
  • No not on a different axes. On a different figure. It is like having each of those three different graphs in different figures. – krazzy Oct 27 '14 at 22:31

1 Answers1

2

Do you mean something like this?

import numpy as np
import matplotlib.pyplot as plt

plt.ion()

a = np.arange(5)
line1, = plt.plot(a, a**2)  # a new figure instance is opened automatically
line2, = plt.plot(a, a**3-a)
line3, = plt.plot(a, 4*a-a**2/2.)

fig_handle = plt.figure()  # Force a new figure instance to open
plt.plot(a, a**2) # This will replot 'line1', but in this new figure instance.

If not, please update your question, perhaps showing the code you already have. Note that this is information you could find on the matplotlib pyplot tutorial.

Oliver W.
  • 13,169
  • 3
  • 37
  • 50
  • Yes. That is how I want it, but my plots are plotted by just using one line of code which is `plot(a,b, label=str(meters))`. The "meters" part is what those three lines represent. I want to use one of those "meters" value to plot one of the graphs from those three curves. It may not be that easy to do it with my code because i have a function and there two loops inside. – krazzy Oct 27 '14 at 22:55
  • Okay. There is an array of values. For ex: `p=[1,2,3,4]`. I have `z = p + b`, where `b = 10`. I graph `plot(b,z)`. I only want to graph the value `p = 2` in the `plot(b,z)` after graphing it with all the four values. The second figure only with `p = 2`. – krazzy Oct 27 '14 at 23:05
  • That's not correct code: you're adding an integer (b) to a basic python array, which will result in a TypeError. Also, when you say you want to graph the value where p equals 2 (`p==2`), does that mean you just want to plot a single datapoint so `(2, 12)`? – Oliver W. Oct 27 '14 at 23:12
  • Well, I am just trying to give you an example. For my code it is curve, not a point, but you do get my point don't you? My code works fine without errors. – krazzy Oct 27 '14 at 23:28
  • No, I don't get your point. Please update your question to make your point more clear. Looking at your code might help. – Oliver W. Oct 27 '14 at 23:30
  • I am sorry, but I can't put it here. It is for my assignment. What if a student from my class finds it? It is not worth taking a risk. – krazzy Oct 28 '14 at 00:09
  • Then I suggest you read the link I provided and improve your knowledge of python and [how to ask a good question](https://stackoverflow.com/help/how-to-ask). – Oliver W. Oct 28 '14 at 00:19