Python Forum
plotting 2 different set of data in a single plot with shared axes.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plotting 2 different set of data in a single plot with shared axes.
#1
Hi..
I have 2 different sets of data like, x1=[1,2,3,4,5],y1=[some corresponding data] and x2=[6,7,8,9,10],y2=[some corresponding data].
How can i plot these in a single plot with shared axes?

to be specific, these are my data:
x1=[1, 3, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4, 1, 5, 2, 3, 4]
y1=[1, 1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 14, 15, 16, 17, 18, 18, 19, 20, 21, 22, 22, 23, 24, 25, 26, 26, 27, 28, 29, 30, 30, 31, 32, 33, 34, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 50, 51, 52, 53, 54, 54, 55, 56, 57, 58, 58, 59, 60, 61, 62, 62, 63, 64, 65, 66, 66, 67, 68, 69, 70, 70, 71, 72, 73, 74, 74, 75, 76, 77, 78, 78, 79, 80, 81, 82, 82, 83, 84, 85, 86, 86, 87, 88, 89, 90, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 98, 99, 100, 101, 102, 102, 103, 104]

x2=[6, 9, 13, 7, 11, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 8, 13, 6, 9, 10, 7, 11, 12, 10, 7, 11, 12, 10, 7, 11, 12, 10, 12, 11, 7, 9, 8, 11, 11, 12, 10, 10, 12, 7, 10, 11, 8, 8, 11, 10, 7, 11, 8, 11, 12, 7, 12, 7, 11, 7, 12, 10, 12]

y2=[1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 10, 10, 11, 11, 11, 11, 12, 12, 13, 13, 14, 14, 14, 14, 15, 15, 16, 16, 17, 17, 17, 17, 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 22, 22, 23, 23, 23, 23, 24, 24, 25, 25, 26, 26, 26, 26, 27, 27, 28, 28, 29, 29, 29, 29, 30, 30, 31, 31, 32, 32, 32, 32, 33, 33, 34, 34, 35, 35, 35, 35, 36, 36, 37, 37, 38, 38, 38, 38, 39, 39, 40, 40, 41, 41, 41, 41, 42, 42, 43, 43, 44, 44, 44, 44, 45, 45, 46, 46, 47, 47, 47, 47, 48, 48, 49, 49, 50, 50, 50, 50, 51, 51, 52, 52, 53, 53, 53, 53, 54, 54, 55, 55, 56, 56, 56, 56, 57, 57, 58, 58, 59, 59, 59, 59, 60, 60, 61, 61, 62, 62, 62, 62, 63, 63, 64, 64, 65, 65, 65, 65, 66, 66, 67, 67, 68, 68, 68, 68, 69, 69, 70, 70, 71, 71, 71, 71, 72, 72, 73, 73, 74, 74, 74, 74, 75, 75, 76, 76, 77, 77, 77, 77, 78, 78, 79, 79, 80, 80, 80, 80, 81, 81, 82, 82, 83, 83, 83, 83, 84, 84, 85, 85, 86, 86, 86, 86, 87, 87, 88, 88, 89, 89, 89, 89, 90, 90, 91, 91, 92, 92, 92, 92, 93, 93, 94, 94, 95, 95, 95, 95, 96, 96, 97, 97, 98, 98, 98, 98, 99, 99, 100, 100, 101, 101, 101, 101, 102, 102, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 105, 105, 105, 106, 106, 106, 106, 107, 107, 107, 108, 108, 108, 109, 109, 109, 110, 110, 110, 110, 111, 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114]


please help...
Reply
#2
What have you tried? Have you looked at Matplotlib?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
(Mar-21-2018, 12:23 PM)sparkz_alot Wrote: What have you tried? Have you looked at Matplotlib?
Yea i did.

fig=plt.figure()
ax=fig.add_subplot(111,label="1")
ax2=fig.add_subplot(111,label="2",frame_on=False)
ax.plot([t1],[i1],marker='.',markersize=3,color='blue')
ax.set_xlabel("Time (ms)-id2", color='blue')
ax.set_ylabel("Neuron Index-id2", color='blue')
ax.tick_params(axis='x', colors='blue')
ax.tick_params(axis='y', colors='blue')
ax2.plot([t2],[i2],marker='.',markersize=3,color='red')
ax2.xaxis.tick_top()
ax2.yaxis.tick_right()
ax2.set_xlabel('Time (ms)-id 3', color="red") 
ax2.set_ylabel('Neuron Index_id 3', color="red")       
ax2.xaxis.set_label_position('top') 
ax2.yaxis.set_label_position('right') 
ax2.tick_params(axis='x', colors="red")
ax2.tick_params(axis='y', colors="red")
doing like this i get inter-digitated plot. ie, the second axis(for x2 and y2) starts with 6.
I want to plot these with a single shared axis rather than 2 axes.

something like this.

Attached Files

Thumbnail(s)
   
Reply
#4
x1 = [1,2,3,4,5]
x2 = list(reversed(x1))
y1 = [10, 20, 30, 40, 50]
y2 = [100, 200, 300, 400, 500]

# x and y must have the same length.

plt.plot(x1, y1)
plt.plot(x2, y2)
plt.show()
Matplotlib seems to make the mapping automatically.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
(Mar-21-2018, 01:29 PM)DeaD_EyE Wrote: x1 = [1,2,3,4,5]
x2 = list(reversed(x1))
y1 = [10, 20, 30, 40, 50]
y2 = [100, 200, 300, 400, 500]

# x and y must have the same length.

plt.plot(x1, y1)
plt.plot(x2, y2)
plt.show()

Thank you so much...its working.. I seemed to have complicated the code too much.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Likert survey data plot error Andrzej_Andrzej 6 1,414 Jul-16-2023, 10:11 PM
Last Post: deanhystad
  Plot a pandas data fram via pyqtgraph with an modul import and qt designer widget Nietzsche 0 847 May-29-2023, 02:42 PM
Last Post: Nietzsche
  Create simple live plot of stock data dram 2 2,921 Jan-27-2023, 04:34 AM
Last Post: CucumberNox
Thumbs Up Python 3 Jupyter notebook ternary plot data nicholas 0 938 Jan-21-2023, 05:01 PM
Last Post: nicholas
  Need help on how to include single quotes on data of variable string hani_hms 5 2,030 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  Multiple user defined plots with secondary axes using for loop maltp 1 1,450 Apr-30-2022, 10:19 AM
Last Post: maltp
  plotting 3d axes estera 0 1,805 Nov-26-2021, 11:36 AM
Last Post: estera
  Presenting multiline data into single line aaronbuhu 1 1,805 Aug-05-2021, 10:57 AM
Last Post: jamesaarr
  [Solved] Plotting data from txt file Laplace12 1 1,819 Jul-06-2021, 07:14 AM
Last Post: Laplace12
  Plotting sum of data files using simple code Laplace12 3 3,043 Jun-16-2021, 02:06 PM
Last Post: BashBedlam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020