How to move lines in matplotlib plots?


doctor

I am trying to plot two lists in python, one is test1and the other is predictions1.

I want the first 150 items of the test1list to be plotted and then the items 101-150 predictions1of the list so that the two plots are on top of each other. Here is what I have tried:

import matplotlib.pyplot as plt
plt.figure(figsize=(15,8))
plt.plot(test1[1:150])
plt.plot(predictions1[101:150], color='red')
plt.show()

But the result I get is:enter image description here

Obviously this is not what I want to achieve as I want the red plot to be superimposed on the blue plot at the end. please help.

David

The idea is to create a list of numbers to use as x data between 0 and 150:

x_data = range(150)

Then slice it so that for the first set of data, the x-axis uses the numbers 0 to 149. Then, slice the second set of data to use the numbers 100 to 149.

plt.plot(x_data[:], test1[:150])
plt.plot(x_data[100:], predictions1[100:150], color='red')

Note that Python indices start at 0, not 1

Related


How to move lines in matplotlib plots?

Doctor I am trying to plot two lists in python, one is test1and the other is predictions1. I want the first 150 items of the test1list to be plotted and then the items 101-150 predictions1of the list so that the two plots are on top of each other. Here is what

How to move lines in matplotlib plots?

Doctor I am trying to plot two lists in python, one is test1and the other is predictions1. I want the first 150 items of the test1list to be plotted and then the items 101-150 predictions1of the list so that the two plots are on top of each other. Here is what

How to move lines in matplotlib plots?

doctor I am trying to plot two lists in python, one is test1and the other is predictions1. I want the first 150 items of the test1list to be plotted and then the items 101-150 predictions1of the list so that the two plots are on top of each other. Here is what

How to shade lines behind surface plots in matplotlib?

Ethunxxx I want to plot data through a colormap on a sphere using Matplotlib. Also, I want to add a 3D line graph. My code so far is this: import matplotlib import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np NPoints_Ph

How to color circular lines in polar plots (matplotlib)

Sam Comber I am trying to color the circle line corresponding to 0 in a polar plot. Here is what I am trying to achieve: Regarding this related question ( Hatching line segments between two lines on a polar axis (matplotlib) ) ax.fill_betweenis for filling the

How to shade lines behind surface plots in matplotlib?

Ethunxxx I want to plot data through a colormap on a sphere using Matplotlib. Also, I want to add a 3D line graph. My code so far is this: import matplotlib import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np NPoints_Ph

How to shade lines behind surface plots in matplotlib?

Ethunxxx I want to plot data through a colormap on a sphere using Matplotlib. Also, I want to add a 3D line graph. My code so far is this: import matplotlib import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np NPoints_Ph

How to shade lines behind surface plots in matplotlib?

Ethunxxx I want to plot data through a colormap on a sphere using Matplotlib. Also, I want to add a 3D line graph. My code so far is this: import matplotlib import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np NPoints_Ph

How to shade lines behind surface plots in matplotlib?

Ethunxxx I want to plot data through a colormap on a sphere using Matplotlib. Also, I want to add a 3D line graph. My code so far is this: import matplotlib import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np NPoints_Ph

How to shade lines behind surface plots in matplotlib?

Ethunxxx I want to plot data through a colormap on a sphere using Matplotlib. Also, I want to add a 3D line graph. My code so far is this: import matplotlib import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np NPoints_Ph

How to color circular lines in polar plots (matplotlib)

Sam Comber I am trying to color the circle line corresponding to 0 in a polar plot. Here is what I am trying to achieve: Regarding this related question ( Hatching line segments between two lines on a polar axis (matplotlib) ) ax.fill_betweenis for filling the

How to draw separate lines for 3D plots on matplotlib

nightshade I have three variables: xs = [1,1,1,2,2,2,3,3,3], ys = [1,2,3,1,2,3,1,2,3], zs = [1,4,9,2,8,18,4,16,36] I want to draw a graph with 3 separate lines by fixing a xs, say x = 2 I want to see lines for ys and zs (where x = 2), which ys = [1,2,3], zs

How to draw lines on plots?

Bubisi I'm trying to draw a line on a line, but the plot doesn't even show. I have checked the values of xPoints and yPoints and they exist. what is the reason? import matplotlib.pyplot as plt import numpy as np def calculateFuncFor(x): ePower = np.e**np.

How to draw lines on plots?

Bubisi I'm trying to draw a line on a line, but the plot doesn't even show. I have checked the values of xPoints and yPoints and they exist. what is the reason? import matplotlib.pyplot as plt import numpy as np def calculateFuncFor(x): ePower = np.e**np.

How to draw lines on plots?

Bubisi I'm trying to draw a line on a line, but the plot doesn't even show. I have checked the values of xPoints and yPoints and they exist. what is the reason? import matplotlib.pyplot as plt import numpy as np def calculateFuncFor(x): ePower = np.e**np.

How to update plots in matplotlib?

Nick name: I'm having trouble redrawing the graph here. I allow the user to specify units in the timescale (x-axis) and then recalculate and call this function plots(). I want the graph to just be updated, not append another graph to it. def plots(): globa

How to update plots in matplotlib?

Nick name: I'm having trouble redrawing the graph here. I allow the user to specify units in the timescale (x-axis) and then recalculate and call this function plots(). I want the graph to just be updated, not append another graph to it. def plots(): globa

How matplotlib plots strings

Casivio I ran into a problem when I realized I was plotting string data and my plot was not reflecting the data I was working on. It seems that matplotlib.pyplot doesn't generate an error when passing a string value and keeps plotting something, but what is it

How matplotlib plots strings

Casivio I ran into a problem when I realized I was plotting string data and my plot was not reflecting the data I was working on. It seems that matplotlib.pyplot doesn't generate an error when passing a string value and keeps plotting something, but what is it

How matplotlib plots strings

Casivio I ran into a problem when I realized I was plotting string data and my plot was not reflecting the data I was working on. It seems that matplotlib.pyplot doesn't generate an error when passing a string value and keeps plotting something, but what is it

How to overlap plots in matplotlib?

poor python programmer I would like to know how to overlap these two plots in matplotlib. One is a plot with dots and the other named "trendlijn" is a straight line. I tried using alpha but it didn't work. Does anyone have a suggestion for me? I'm not very goo

How to update plots in matplotlib?

Nick name: I'm having trouble redrawing the graph here. I allow the user to specify units in the timescale (x-axis) and then recalculate and call this function plots(). I want the graph to just be updated, not append another graph to it. def plots(): globa

How matplotlib plots strings

Casivio I ran into a problem when I realized I was plotting string data and my plot was not reflecting the data I was working on. It seems that matplotlib.pyplot doesn't generate an error when passing a string value and keeps plotting something, but what is it

How matplotlib plots strings

Casivio I ran into a problem when I realized I was plotting string data and my plot was not reflecting the data I was working on. It seems that matplotlib.pyplot doesn't generate an error when passing a string value and keeps plotting something, but what is it

How matplotlib plots strings

Casivio I ran into a problem when I realized I was plotting string data and my plot was not reflecting the data I was working on. It seems that matplotlib.pyplot doesn't generate an error when passing a string value and keeps plotting something, but what is it

How matplotlib plots strings

Casivio I ran into a problem when I realized I was plotting string data and my plot was not reflecting the data I was working on. It seems that matplotlib.pyplot doesn't generate an error when passing a string value and keeps plotting something, but what is it