I want to change the color of the line graph I drew in Pandas.DataFrame.Plot from the middle of the x-axis.

Asked 2 years ago, Updated 2 years ago, 45 views

I would like to change the color of the line graph I drew in Pandas.DataFrame.Plot from the middle of the x-axis.
For example, if the x-axis is 3 or more below, how do I change the color of the line to red?
Please let me know if you can't find the same question.

import pandas as pd

a = {'x-axis': [1,2,3,4,5], 'y-axis': [1,2,3,4,5]}
df=pd.DataFrame(data=a)
df.plot(x='x-axis', y='y-axis')

Enter a description of the image here

python python3 pandas

2022-09-30 19:43

1 Answers

What about this?(Reference)
  

import pandas as pd
import matplotlib.pyplot asplt
a = {'x-axis': [1,2,3,4,5], 'y-axis': [1,2,3,4,5]}
df=pd.DataFrame(data=a)
N = 3.0
ax=df['x-axis'].plot()
df.loc [df.index>=N, 'x-axis'].plot (color='r', ax=ax)
ax=df.plot(x='x-axis', y='y-axis')
plt.show()

Enter a description of the image here


2022-09-30 19:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.