-1

I have an data on excel . enter image description here . I filtered some columns and rows from this excel file and wrote this code ;

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.dates as mdates


df=pd.read_excel("Julian_iski_data_python.xlsx")

df = df[["prSM [db]", "year", "T(degC)","Station"]]
df = df.loc[df["prSM [db]"] == 1]
df = df.loc[df["Station"].isin(["M8", "M14", "M23", "MY2"])]

fig = plt.figure(figsize=(10,10))
axes = fig.add_axes([0.04,0.06,0.95,0.91])

sns.scatterplot(data=df, x="year", y="T(degC)", hue="Station",style="Station")
sns.lineplot(data=df, x="year", y="T(degC)", hue="Station",style="Station")
axes.xaxis.set_major_locator(mdates.YearLocator(1))
axes.set_xlabel("Time")
axes.grid()
plt.show()

And ı got this graph. enter image description here . My question is :
In the graph, I got the x-axis from the column named "year" . and ı also have new_year column. enter image description here . If the year values ​​in the column named "new year" match the "year" on the x-axis of the graph, I want to put a grid there. How can ı do this ? If I didn't explain myself well, I would like to explain it with a photo.enter image description here

1 Answers1

0

If you wanted to specifically mark the year values that "new year" match the "year" on the x-axis of the graph, you could add a vertical line on those key values. You could go about it like this:

import numpy as np
import matplotlib.pyplot as plt

if __name__ == "__main__":

    # Create a sine wave
    t = 20
    fs = 10
    samples = np.linspace(0, t, int(fs*t), endpoint=False)
    wave = np.sin(samples)

    # Plot function
    fig, axs = plt.subplots()
    axs.plot(wave)
    axs.grid()
    axs.set_ylim([-1.25, 1.25])

    # Mark where we want the extra vertical lines
    vlines = [60, 80, 127]
    # Add the vertical line
    axs.vlines(x=vlines, ymin=-1.25, ymax=1.25, colors='black', linestyles="--")

    plt.show()

An example with vertical lines

If you are more interested in spacing the grid so that the grid lines fall on those key values, you could take a look at this post: PyPlot - Setting grid line spacing for plot.

Cheers!