Saturday 13 July 2024

Different Line graph plot using Python

 

5. Interactive Line Graph using Plotly

import plotly.express as px


# Sample data

data = {

    'x': [1, 2, 3, 4, 5],

    'y': [2, 3, 5, 7, 11]

}


# Creating an interactive line plot

fig = px.line(data, x='x', y='y', 

              title='Interactive Line Graph using Plotly', markers=True)

fig.show()


4. Line Graph using Seaborn

import seaborn as sns

import matplotlib.pyplot as plt


# Sample data

data = {

    'x': [1, 2, 3, 4, 5],

    'y': [2, 3, 5, 7, 11]

}


# Creating a Seaborn line plot

sns.lineplot(x='x', y='y', data=data, marker='o')

plt.title('Line Graph using Seaborn')

plt.xlabel('X-axis')

plt.ylabel('Y-axis')

plt.grid(True)

plt.show()

3. Line Graph with Error Bars using Matplotlib

import matplotlib.pyplot as plt

import numpy as np


# Sample data

x = np.array([1, 2, 3, 4, 5])

y = np.array([2, 3, 5, 7, 11])

yerr = np.array([0.5, 0.4, 0.3, 0.2, 0.1])


# Plotting the line graph with error bars

plt.errorbar(x, y, yerr=yerr, fmt='-o', capsize=5)

plt.title('Line Graph with Error Bars')

plt.xlabel('X-axis')

plt.ylabel('Y-axis')

plt.grid(True)

plt.show()

2. Multiple Line Graphs using Matplotlib

import matplotlib.pyplot as plt


# Sample data

x = [1, 2, 3, 4, 5]

y1 = [2, 3, 5, 7, 11]

y2 = [1, 4, 6, 8, 10]


# Plotting multiple line graphs

plt.plot(x, y1, label='Line 1', marker='o')

plt.plot(x, y2, label='Line 2', marker='s')

plt.title('Multiple Line Graphs')

plt.xlabel('X-axis')

plt.ylabel('Y-axis')

plt.legend()

plt.grid(True)

plt.show()

1. Basic Line Graph using Matplotlib

import matplotlib.pyplot as plt


# Sample data

x = [1, 2, 3, 4, 5]

y = [2, 3, 5, 7, 11]


# Plotting the line graph

plt.plot(x, y, marker='o')

plt.title('Basic Line Graph')

plt.xlabel('X-axis')

plt.ylabel('Y-axis')

plt.grid(True)

plt.show()

0 Comments:

Post a Comment

Popular Posts

Categories

AI (29) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (121) C (77) C# (12) C++ (82) Course (67) Coursera (195) Cybersecurity (24) data management (11) Data Science (100) Data Strucures (7) Deep Learning (11) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Pandas (3) PHP (20) Projects (29) Python (831) Python Coding Challenge (277) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (41) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses