Python Forum
Multiple Line Chart Plotting
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple Line Chart Plotting
#1
Hello All,

I am trying to plot multiple lines on a chart using the following data and would be grateful for any assistance.
I have a set of daily counts of mobile app 1st open event by OS and Date with Daily Totals.
I would like to have 3 line plots on the same chart by day.

I have 2 lines appearing but the Date values are not appearing the right order on the X axis, I suspect they are beign treated as strings.

Happy to scrap my program completely if there is an easier way I suspect there will be

Thanks for helping a newbie


import plotly.express as px 
from chart_studio.plotly import iplot
import plotly.offline as pyo
import plotly.graph_objs as go
import pandas as pd 
import numpy as np 
import os

print(os.getcwd())
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
print(os.getcwd())

df = pd.read_csv('dailycounts.csv')

isIOS = df['OS'] == 'IOS'
isAndroid = df['OS'] == 'ANDROID'
#  print (IOSList.head())


IOSData = df[isIOS]
AndroidData = df[isAndroid]
# print (IOSData)

trace1 = {
  "line": {"color": "rgba(31,119,180,1)"}, 
  "mode": "lines", 
  "name": 'IOS', 
  "type": "scatter", 
  "x": IOSData['TheDate'],
  "y": IOSData['TheCount'],
    "xaxis": "x", 
  "yaxis": "y"
}

trace2 = {
  "line": {"color": "rgba(31,119,180,1)"}, 
  "mode": "lines", 
  "name": 'Android', 
  "type": "scatter", 
  "x": AndroidData['TheDate'],
  "y": AndroidData['TheCount'],
    "xaxis": "x", 
  "yaxis": "y"
}
data =[trace1,trace2]
# print ([trace1])

layout = {
  "title": "First Opens", 
  "xaxis": {
    "title": "Date", 
    "domain": [0, 1], 
    "rangeselector": {"buttons": [
        {
          "step": "month", 
          "count": 3, 
          "label": "3 mo", 
          "stepmode": "backward"
        }, 
        {
          "step": "month", 
          "count": 6, 
          "label": "6 mo", 
          "stepmode": "backward"
        }, 
        {
          "step": "year", 
          "count": 1, 
          "label": "1 yr", 
          "stepmode": "backward"
        }, 
        {
          "step": "year", 
          "count": 1, 
          "label": "YTD", 
          "stepmode": "todate"
        }, 
        {"step": "all"}
      ]}
  }, 
  "yaxis": {
    "title": "Count", 
    "domain": [0, 1]
  }, 
  "margin": {
    "b": 40, 
    "l": 60, 
    "r": 10, 
    "t": 25
  }
}
# fig = Figure(data=data, layout=layout)
pyo.plot(data, filename='test9.html')
OS,TheDate,TheCount
ANDROID,1-Nov-19,85
ANDROID,2-Nov-19,69
ANDROID,3-Nov-19,157
ANDROID,4-Nov-19,157
ANDROID,5-Nov-19,96
ANDROID,6-Nov-19,117
ANDROID,7-Nov-19,150
ANDROID,8-Nov-19,299
ANDROID,9-Nov-19,321
ANDROID,10-Nov-19,272
ANDROID,11-Nov-19,188
ANDROID,12-Nov-19,156
ANDROID,13-Nov-19,120
ANDROID,14-Nov-19,319
ANDROID,15-Nov-19,132
ANDROID,16-Nov-19,261
ANDROID,17-Nov-19,294
ANDROID,17-Oct-19,11
ANDROID,18-Nov-19,151
ANDROID,18-Oct-19,10
ANDROID,19-Nov-19,170
ANDROID,19-Oct-19,10
ANDROID,20-Nov-19,134
ANDROID,20-Oct-19,5
ANDROID,21-Nov-19,124
ANDROID,21-Oct-19,8
ANDROID,22-Nov-19,138
ANDROID,22-Oct-19,16
ANDROID,23-Nov-19,131
ANDROID,23-Oct-19,13
ANDROID,24-Nov-19,159
ANDROID,24-Oct-19,9
ANDROID,25-Oct-19,9
ANDROID,26-Oct-19,10
ANDROID,27-Oct-19,12
ANDROID,28-Oct-19,40
ANDROID,29-Oct-19,127
ANDROID,30-Oct-19,125
ANDROID,31-Oct-19,116
IOS,1-Nov-19,119
IOS,2-Nov-19,115
IOS,3-Nov-19,182
IOS,4-Nov-19,230
IOS,5-Nov-19,135
IOS,6-Nov-19,186
IOS,7-Nov-19,158
IOS,8-Nov-19,379
IOS,9-Nov-19,410
IOS,10-Nov-19,456
IOS,11-Nov-19,373
IOS,12-Nov-19,388
IOS,13-Nov-19,387
IOS,14-Nov-19,630
IOS,15-Nov-19,260
IOS,16-Nov-19,286
IOS,17-Nov-19,425
IOS,17-Oct-19,24
IOS,18-Nov-19,507
IOS,18-Oct-19,32
IOS,19-Nov-19,386
IOS,19-Oct-19,16
IOS,20-Nov-19,535
IOS,20-Oct-19,21
IOS,21-Nov-19,398
IOS,21-Oct-19,18
IOS,22-Nov-19,256
IOS,22-Oct-19,38
IOS,23-Nov-19,168
IOS,23-Oct-19,26
IOS,24-Nov-19,407
IOS,24-Oct-19,35
IOS,25-Oct-19,24
IOS,26-Oct-19,21
IOS,27-Oct-19,13
IOS,28-Oct-19,102
IOS,29-Oct-19,178
IOS,30-Oct-19,215
IOS,31-Oct-19,171
TOTAL,1-Nov-19,204
TOTAL,2-Nov-19,184
TOTAL,3-Nov-19,339
TOTAL,4-Nov-19,387
TOTAL,5-Nov-19,231
TOTAL,6-Nov-19,303
TOTAL,7-Nov-19,308
TOTAL,8-Nov-19,678
TOTAL,9-Nov-19,731
TOTAL,10-Nov-19,728
TOTAL,11-Nov-19,561
TOTAL,12-Nov-19,544
TOTAL,13-Nov-19,507
TOTAL,14-Nov-19,949
TOTAL,15-Nov-19,392
TOTAL,16-Nov-19,547
TOTAL,17-Nov-19,719
TOTAL,17-Oct-19,35
TOTAL,18-Nov-19,658
TOTAL,18-Oct-19,42
TOTAL,19-Nov-19,556
TOTAL,19-Oct-19,26
TOTAL,20-Nov-19,669
TOTAL,20-Oct-19,26
TOTAL,21-Nov-19,522
TOTAL,21-Oct-19,26
TOTAL,22-Nov-19,394
TOTAL,22-Oct-19,54
TOTAL,23-Nov-19,299
TOTAL,23-Oct-19,39
TOTAL,24-Nov-19,566
TOTAL,24-Oct-19,44
TOTAL,25-Oct-19,33
TOTAL,26-Oct-19,31
TOTAL,27-Oct-19,25
TOTAL,28-Oct-19,142
TOTAL,29-Oct-19,305
TOTAL,30-Oct-19,340
TOTAL,31-Oct-19,287
Reply
#2
Plot multiple lines on one chart with different style Python matplotlib. Sometimes we need to plot multiple lines on one chart using different styles such as dot, line, dash, or maybe with different colour as well. It is quite easy to do that in basic python plotting using matplotlib library.visit
Another way to plot multiple lines is to plot them one by one, using the built-in R functions points () and lines (). The code below demonstrates an example of this approach: #generate an x-axis along with three data series x <- c (1,2,3,4,5,6) y1 <- c (2,4,7,9,12,19) y2 <- c (1,5,9,8,9,13) y3 <- c (3,6,12,14,17,15) #plot the first data series using plot () plot (x, y1, type="o", col="blue", pch="o", ylab="y", lty=1) #add second data series to the same chart using points () and lines ...i hope this is helpful if not so anybody share complite info like this share visit link where i see it
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create Excel Line Chart Programmatically dee 3 1,178 Dec-30-2022, 08:44 PM
Last Post: dee
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,655 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  matplotlib Plotting smooth line with nans mikisDeWitte 4 3,099 Mar-11-2022, 02:40 PM
Last Post: mikisDeWitte
Lightbulb Multiple inputs on the same line (beginner) dementshuk 9 2,775 Sep-03-2021, 02:21 PM
Last Post: dementshuk
  Plotting Multiple files ! Helen_145 1 2,710 Jun-26-2021, 03:28 PM
Last Post: snippsat
  Multiple Plotting in Same PLot quest 0 1,796 Apr-18-2021, 10:29 AM
Last Post: quest
  How to print string multiple times on new line ace19887 7 5,715 Sep-30-2020, 02:53 PM
Last Post: buran
  Taking Multiple Command Line Argument Input bwdu 6 4,019 Mar-29-2020, 05:52 PM
Last Post: buran
  Multiple Line Input helenaxoxo 4 2,919 Dec-02-2019, 11:06 PM
Last Post: helenaxoxo
  Write HEX into file in multiple line jacklee26 4 4,376 Nov-17-2017, 10:18 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020