Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

Line Chart Matplotlib || Lesson 3.3 || Python for Data Science || Learning Monkey ||

Автор: Learning Monkey

Загружено: 2021-08-11

Просмотров: 323

Описание:

Line Chart Matplotlib
In this class, We discuss Line Chart Matplotlib.
The reader should have prior knowledge of the bar chart. Click here.
We use the superstore data set. The data set is discussed in our previous class.
Line Chart Matplotlib
A line chart is a graphical representation used in connecting a series of data points with a continuous line.
In our data set, we use a line chart to display year-wise total sales.
With this continuous line, we will understand how sales are going in the last ten years.
To get the year-wise sale details, we use the column order date.
The column order date is of type DateTime in pandas.
We need to extract the year from the date. The methods used to extract the year from the date are discussed here.
The program to extract the year from the date and placing in a new column is given below.
df=pd.read_excel('sampledata.xls',sheet_name='Orders')
print(df.head())

df['year'] = df[;'Order Date'].dt.year
print(df.head())

grouping sales year wise
temp=pd.DataFrame(df.groupby(['year'])['Sales'].agg('sum'))
print(temp)
x=temp.index
y=temp['Sales'].values
print(x)

Simple Line Plot
To construct a line plot, we use the method plot from matplotlib.pyplot.
In the example, we use year on the x-axis and total year-wise sales on the y-axis.
The variable x contains years, and the variable y contain total sales.
We use the parameter color to give the line color.
The simple line chart code and output are shown below.
line plot code
import matplotlib.pyplot as plt
z=plt.figure(num=1,figsize=(10,5))
plt.plot(x, y, color ='blue')
plt.xticks(x)
plt.xlabel("Year")
plt.ylabel("Sum of sale")
plt.title("Year Wise Total Sale")
plt.show()

Multiple Lines
We can plot multiple lines in a graph.
We consider a total sale and furniture sale year-wise to plot multiple lines.
Below is the code to show multiple lines.
plot Multiple lines
we are taking furniture sale year wise to plot
temp1=pd.DataFrame(df.groupby(['year','Category'])['Sales'].agg('sum'))
print(temp1)
x1=temp1.index
print(x1)

temp2=temp1.xs('Furniture', level='Category')
print(temp2)
y1=temp2['Sales'].values
print(y1)

Multiple line plot code
import matplotlib.pyplot as plt
z=plt.figure(num=1,figsize=(10,5))
plt.plot(x, y, color ='blue')
plt.plot(x,y1,color='red')
plt.xticks(x)
plt.xlabel("Year")
plt.ylabel("Sum of sale")
plt.title("Year Wise Total Sale")
plt.legend(['Total','Furniture'],loc=0)
plt.show()

We notice the furniture sale line is almost flat. By looking at the output of multiple line charts
We are not having clarity about the exact sale value because the y-axis unit measure is large.
We can change the unit measure of the y-axis using yticks. We discuss how to change units in our next class.
We used the plot function multiple times to plot the line chart twice.
Line Width Parameter
We use the line width parameter to increase or decrease the line width.
The below code will increase the line width of the total sale.
Line width and line style
import matplotlib.pyplot as plt
z=plt.figure(num=1,figsize=(10,5))
plt.plot(x, y, color ='blue',linewidth=4)
plt.plot(x,y1,color='red',linestyle=':')#for dash line use --
plt.xticks(x)
plt.xlabel("Year")
plt.ylabel("Sum of sale")
plt.title("Year Wise Total Sale")
plt.legend(['Total','Furniture'],loc=0)
plt.show()
Short cuts and Markers
We can show dotted lines, dashed lines, etc.
Short cuts are used to show the line options.
Markers are used to mark the data point of our data.
Marker o is used to mark circles at the data point.
The marker s is used to mark the square at the data point.
The color, line type, and marker is shown using a shortcut in the plot method.
The below code shows the shortcuts and markers used in the plot method.
Short cuts and Markers
import matplotlib.pyplot as plt
z=plt.figure(num=1,figsize=(10,5))
plt.plot(x, y, 'b-o')
plt.plot(x,y1,'r--s')
plt.xticks(x)
plt.xlabel("Year")
plt.ylabel("Sum of sale")
plt.title("Year Wise Total Sale")
plt.legend(['Total','Furniture'],loc=0)
plt.show()

Below showing some of the markers used in python.
The reader should try these markers for better practice.
Few Marker shapes supported by matplotlib



Link for playlists:
   / @learningmonkey  


Link for our website: https://learningmonkey.in

Follow us on Facebook @   / learningmonkey  

Follow us on Instagram @   / learningmonkey1  

Follow us on Twitter @   / _learningmonkey  

Mail us @ [email protected]

Line Chart Matplotlib || Lesson 3.3 || Python for Data Science || Learning Monkey ||

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

array(10) { [0]=> object(stdClass)#4956 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "fpNzs62uAIQ" ["related_video_title"]=> string(99) "Changing Coordinate Axis Units Matplotlib || Lesson 3.4 | Python for Data Science | Learning Monkey" ["posted_time"]=> string(21) "3 года назад" ["channelName"]=> string(15) "Learning Monkey" } [1]=> object(stdClass)#4929 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "7VAFU88VGlo" ["related_video_title"]=> string(79) "Matplotlib Full Tutorial | Matplotlib - Machine Learning - Matplotlib Explained" ["posted_time"]=> string(21) "3 года назад" ["channelName"]=> string(11) "WsCube Tech" } [2]=> object(stdClass)#4954 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "nQADDayjqSE" ["related_video_title"]=> string(78) "Multiple Line Graph Using Python | Matplotlib Library | Step By Step Tutorial" ["posted_time"]=> string(21) "2 года назад" ["channelName"]=> string(10) "Lotusamaze" } [3]=> object(stdClass)#4961 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "Go0jBRVqmEI" ["related_video_title"]=> string(53) "Bar Graph | Bar Chart | Matplotlib | Python Tutorials" ["posted_time"]=> string(21) "4 года назад" ["channelName"]=> string(16) "Amulya's Academy" } [4]=> object(stdClass)#4940 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "jvzRpgn0Uqs" ["related_video_title"]=> string(99) "Проходим официальную сертификацию на Linux в ГосУслугах" ["posted_time"]=> string(22) "11 дней назад" ["channelName"]=> string(31) "Максим Сергеевич" } [5]=> object(stdClass)#4958 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "5psoDztexlI" ["related_video_title"]=> string(94) "xticks( ) , yticks( ) , xlabel( ) , ylabel( ) , xlim( ) , ylim( ) IN MATPLOTLIB || MATPLOTLIB" ["posted_time"]=> string(21) "3 года назад" ["channelName"]=> string(24) "Sundeep Saradhi Kanthety" } [6]=> object(stdClass)#4953 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "7N0HGBllD6s" ["related_video_title"]=> string(106) "Китай атаковал самолёт НАТО / Резкое обращение президента" ["posted_time"]=> string(21) "4 часа назад" ["channelName"]=> string(10) "NEXTA Live" } [7]=> object(stdClass)#4963 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "i-FFVM4cIXQ" ["related_video_title"]=> string(138) "База по Базам Данных - Storage (Индексы, Paging, LSM, B+-Tree, R-Tree) | Влад Тен Систем Дизайн" ["posted_time"]=> string(25) "3 недели назад" ["channelName"]=> string(15) "Влад Тен" } [8]=> object(stdClass)#4939 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "nFvoGe8bPE4" ["related_video_title"]=> string(124) "Как вас превратили в товар. Тёмная сторона экономики внимания | ФАЙБ" ["posted_time"]=> string(22) "23 часа назад" ["channelName"]=> string(8) "Файб" } [9]=> object(stdClass)#4957 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "5g-MHZ0MzZY" ["related_video_title"]=> string(56) "Экспресс курс по python за 7 часов!" ["posted_time"]=> string(21) "3 года назад" ["channelName"]=> string(17) "Python Hub Studio" } }
Changing Coordinate Axis Units Matplotlib || Lesson 3.4 | Python for Data Science | Learning Monkey

Changing Coordinate Axis Units Matplotlib || Lesson 3.4 | Python for Data Science | Learning Monkey

Matplotlib Full Tutorial | Matplotlib - Machine Learning - Matplotlib Explained

Matplotlib Full Tutorial | Matplotlib - Machine Learning - Matplotlib Explained

Multiple Line Graph Using Python  | Matplotlib Library | Step By Step Tutorial

Multiple Line Graph Using Python | Matplotlib Library | Step By Step Tutorial

Bar Graph | Bar Chart | Matplotlib | Python Tutorials

Bar Graph | Bar Chart | Matplotlib | Python Tutorials

Проходим официальную сертификацию на Linux в ГосУслугах

Проходим официальную сертификацию на Linux в ГосУслугах

xticks( ) , yticks( ) ,  xlabel( ) , ylabel( ) , xlim( ) , ylim( ) IN MATPLOTLIB || MATPLOTLIB

xticks( ) , yticks( ) , xlabel( ) , ylabel( ) , xlim( ) , ylim( ) IN MATPLOTLIB || MATPLOTLIB

Китай атаковал самолёт НАТО / Резкое обращение президента

Китай атаковал самолёт НАТО / Резкое обращение президента

База по Базам Данных - Storage (Индексы, Paging, LSM, B+-Tree, R-Tree) | Влад Тен Систем Дизайн

База по Базам Данных - Storage (Индексы, Paging, LSM, B+-Tree, R-Tree) | Влад Тен Систем Дизайн

Как вас превратили в товар. Тёмная сторона экономики внимания | ФАЙБ

Как вас превратили в товар. Тёмная сторона экономики внимания | ФАЙБ

Экспресс курс по python за 7 часов!

Экспресс курс по python за 7 часов!

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]