Home > Back-end >  Matplotlib - Show only data that are above a certain value
Matplotlib - Show only data that are above a certain value

Time:09-22

I am using Matplotlib and Pandas to plot data.

However, I want to show on the graph only data that are above a certain value.

import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd

# Importing the data using Pandas
BE = pd.read_csv("BE-4YRS.csv")
FR = pd.read_csv("FR-4YRS.csv")


fig, ax = plt.subplots()
ax.scatter(BE["Week"], BE["percent"], alpha=0.7, c="r", s=BE["percent"]*2, label="Belgium")
ax.scatter(FR["Week"], FR["percent"], alpha=0.7, c="b", s=FR["percent"]*2, label="France")
ax.xaxis.set_major_locator(mdates.WeekdayLocator(interval=1))
plt.legend()
plt.xticks(rotation=45)
plt.grid(True)

I tried with :

for i in BE["percent"]:
    if i > 75:
        print(i)

OUTPUT :

78
100
78
76
77
87

But I can't manage to get the corresponding date to these values

CodePudding user response:

You can do it with:

BE_CFT_18to21 = BE_CFT_18to21[BE_CFT_18to21.percent > 75]
  • Related