Линейный график используется для представления непрерывных данных, зависящих от времени.

Давайте разберемся с помощью примера;

Линейная диаграмма: динамика продаж за 12 месяцев

# Sales data across months
months = np.array(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'])
sales = np.array([241268.56, 184837.36, 263100.77, 242771.86, 288401.05, 401814.06, 258705.68, 456619.94, 481157.24, 422766.63, 555279.03, 503143.69])

Первый импорт важных библиотек: —

import numpy as np
import matplotlib.pyplot as plt

Создать массив;

months = np.array(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'])
sales = np.array([241268.56, 184837.36, 263100.77, 242771.86, 288401.05, 401814.06, 258705.68, 456619.94, 481157.24, 422766.63, 555279.03, 503143.69])

Построение линейного графика;

plt.plot(months,sales)
# adding title to the chart
plt.title(" Trend of sales over the 12 months",color="green")
# labeling the axes
plt.xlabel("Months",color="red")
plt.ylabel("Sales",color="red")
# rotating the tick values of x-axis(The names of the months are not be readable)
plt.xticks(rotation=120)

Применение небольшого алгоритма для переименования чисел, находящихся на оси Y;

tick_y=np.arange(200000,600000,50000)
tick_store=[]
for i in tick_y:
    num=i/100000
    txt=str(num)+"L"
    tick_store.append(txt)
plt.yticks(tick_y,tick_store)    
    
# displating the created plot
plt.show()

Один маленький трюк Итак, мы можем получить точечный график с помощью функции/метода Help of Plot();

#plt.plot(продажи,'ro')

В разделе дня 5 мы изучим «Визуализацию с помощью гистограммы Graph»…..