2

I have 2 existing plots (let's name them plot1 and plot2), generated with matplotlib. These plots are saved as png files. I do not have access to the data.
I want to combine these plots into one: one color for the first, the second using a different color over the other one.
The plots are generated from a really long computation and, as said before, I do not have access to the raw data. I wanted to know if there is some way to get the values from the files and create a "merged" plot.

I've tried what was answered here, but since I can't access the data I haven't been able to make it work for my program.

Community
  • 1
  • 1
SrCalcetinos
  • 23
  • 1
  • 5
  • 1
    Hi, and welcome to SO. Could you elaborate a little more, please: How are the plots currently generated? What format are they in? Are they displayed or saved in some format? Is that process a black box to you (you say you don't have the data)? – Schorsch Aug 12 '14 at 14:32
  • The "original" program gives me a plot for each dataset. The only output it gives me is a scatter plot, that exports as png. The way they are generated is totally unknown for me. – SrCalcetinos Aug 13 '14 at 07:30
  • They are saved into png files – SrCalcetinos Aug 13 '14 at 12:56
  • I think I have an idea. [Check this out](http://stackoverflow.com/questions/4581504/how-to-set-opacity-of-background-colour-of-graph-wit-matplotlib). [And this](http://matplotlib.org/examples/pylab_examples/demo_annotation_box.html). If the scales are the same, it looks like you could change the alpha of one of them to, say, .5 and plot one over the other. – mauve Aug 13 '14 at 15:22
  • @mauve looks promising. You might want to edit your answer to show a minimal working example with two png files. – Schorsch Aug 13 '14 at 17:41
  • Thank you very much! @mauve's idea worked! – SrCalcetinos Aug 14 '14 at 08:20
  • No problem - I was a little too busy at work to come up with a working example, but I'm glad it worked out. – mauve Aug 15 '14 at 18:09

1 Answers1

-2

You could do this:

import matplotlib.pyplot as plt
import math
import numpy as np

data = {}

data['x'] = np.arange(0.01, 10.0, 0.01)
data['y1'] = [math.cos(i) for i in data['x']]
data['y2'] = [math.sin(i) for i in data['x']]

fig, ax1 = plt.subplots()
ax1.plot(data['x'],data['y1'])
ax1.plot(data['x'],data['y2'])

fig.show()

If you wanted to plot with 2 different scales, you would alter slightly:

fig, ax1 = plt.subplots()
ax1.plot(data['x'],data['y1'], 'b')
ax2 = ax1.twinx()
ax2.plot(data['x'],data['y2'], 'g')
mauve
  • 2,707
  • 1
  • 20
  • 34
  • How does this answer the question? The OP states that *I can't access the data* - you don't show how to extract data from one plot and use it in another. – Schorsch Aug 12 '14 at 15:03
  • "I can't access the data" sounds like OP is talking about the linked answer. – mauve Aug 12 '14 at 15:04
  • There is a lot of speculation involved. How about waiting for a clarification before prematurely posting an answer? – Schorsch Aug 12 '14 at 15:06
  • Even regardless of whether or not the OP's data is available, *merging two existing plots* is the essence of the question and there is nothing about that here. – Ajean Aug 12 '14 at 20:22
  • Thanks everybody... As Schorsch and Ajean say, I can't access the data used for making the plot, so the answer isn't useful for me :( – SrCalcetinos Aug 13 '14 at 07:31