Found 10784 Articles for Python

How to save multiple plots into a single HTML file in Python Plotly?

Vani Nalliappan
Updated on 07-Oct-2022 11:17:57

3K+ Views

Plotly is an open-source Python library for creating charts. You can use the features available in Plotly to save multiple plots into a single HTML file. For example, plotly.subplots() method can be used to add multiple plots. Follow the steps given to create subplots with Plotly express. Step 1 Import plotly.graphs_objs module and alias as go import plotly.graphs_objs as go Step 2 Import make_subplots to create subplots. from plotly.subplots import make_subplots Step 3 Import plotly offline plot. from plotly.offline import plot Step 4 Create traces for two scatter plots and store it inside figure. fig.add_trace(go.Scatter(x=[0, 1, 2], y=[5, 6, 7]), ... Read More

How to highlight all the values from a group on hover in Python Plotly?

Vani Nalliappan
Updated on 07-Oct-2022 11:13:57

938 Views

Plotly has features to group data values. You can also highlight all the values from a group on hover. In this tutorial, we will use plotly.io to generate the figures. It contains a lot of methods to customize the charts. Follow the steps given below to highlight all the values from a group on hover. Step 1 Import the plotly.io module and alias as pio. import plotly.io as pio Step 2 Create a list of values to form a dictionary. fonts = ['Arial', 'Arial', 'Courier', 'Arial', 'Courier', 'Arial'] shade = ['bold', 'bold', 'italic', 'italic', 'bold', 'bold'] score = [1, 2, ... Read More

How to change the size of a Dash Graph in Python Plotly?

Vani Nalliappan
Updated on 07-Oct-2022 11:10:13

3K+ Views

Plotly supports two different libraries "Plotly graphs in a Dash app" and "Plotly Graph objects in Plotly Express". Dash is a Python framework and it is used to create interactive web-based dashboard applications. The dash library adds all the required libraries to web-based dashboard applications Import dash core components and html components. Add plotly.express method to generate graphs. Use the Dcc.Graph() method to set the style for height and width coordinates. In this tutorial, we will show how you can add multiple graphs to a Plotly Dash app on a single browser page. Follow the steps given below to generate ... Read More

How to set the range of Y-axis in Python Plotly?

Vani Nalliappan
Updated on 27-Aug-2023 03:45:40

27K+ Views

Plotly supports to the range on both X and Y axis. Let us understand how to set the range of Y-axis in Plotly. plotly.graph_objects is used to generate figures. It contains a lot of methods to customize charts and render a chart in HTML format. Create a numpy module and generate random ranges for both X and Y axis. Create Figure() method to plot X and Y axis with mode as lines Create update_layout() method and set the Y-axis range. Follow the steps given to set the range of Y-axis in Plotly. Step 1 − Import plotly Import ... Read More

How to set the line color in Python Plotly?

Vani Nalliappan
Updated on 07-Oct-2022 10:59:34

15K+ Views

Python Plotly has features that you can use to set the line color in a graph. In this tutorial, let us understand how to set the line color in Plotly. Here, we will use plotly.express to generate the figures. It contains a lot of methods to customize the charts and render a chart in HTML format. To set the line color, we will use the update_traces() method and set line_color with color values. Follow the steps given below to set the line color. Step 1 Import plotly.express module and alias as px. import plotly.express as px Step 2 Create a ... Read More

How to plot multiple figures as subplots in Python Plotly?

Vani Nalliappan
Updated on 07-Oct-2022 10:55:21

11K+ Views

Plotly is an open-source Python library for creating charts. You can use the features available in Plotly to set multiple figures as subplots. In this tutorial, we will use plotly.graph_objects to generate the figures. It contains a lot of methods to customize chart and render a chart into HTML format. For example, plotly.subplots() method can be used to add subplots. Follow the steps given below to create subplots with Plotly express. Step 1 Import plotly.graphs_objs module and alias as go. import plotly.graphs_objs as go Step 2 Import make_subplots to create subplots. from plotly.subplots import make_subplots Step 3 Create subplots ... Read More

How to open a URL by clicking a data point in Python Plotly?

Vani Nalliappan
Updated on 07-Oct-2022 10:51:37

2K+ Views

Plotly supports two different libraries "Plotly graphs in a Dash app" and "Plotly Graph objects and Plotly Express". Dash is a Python framework and it is used to create interactive web-based dashboard applications. For example, dash library adds all the required libraries to web-based dashboard applications. Import dash core components and HTML components. Add plotly.express method to generate graphs. Use the Dcc.Graph() method to set the style for height and width coordinates. Follow the steps given below to open a URL by clicking a data point. Step 1 Import the Dash library. import dash Step 2 Import the Dash ... Read More

How to implement linear classification with Python Scikit-learn?

Gaurav Leekha
Updated on 04-Oct-2022 08:40:49

3K+ Views

Linear classification is one of the simplest machine learning problems. To implement linear classification, we will be using sklearn’s SGD (Stochastic Gradient Descent) classifier to predict the Iris flower species. Steps You can follow the below given steps to implement linear classification with Python Scikit-learn − Step 1 − First import the necessary packages scikit-learn, NumPy, and matplotlib Step 2 − Load the dataset and build a training and testing dataset out of it. Step 3 − Plot the training instances using matplotlib. Although this step is optional, it is good practice to plot the instances for more clarity. Step 4 − Create ... Read More

How to transform Scikit-learn IRIS dataset to 2-feature dataset in Python?

Gaurav Leekha
Updated on 04-Oct-2022 08:38:18

555 Views

Iris, a multivariate flower dataset, is one of the most useful Pyhton scikit-learn datasets. It has 3 classes of 50 instances each and contains the measurements of the sepal and petal parts of three Iris species namely Iris setosa, Iris virginica, and Iris versicolor. Along with that Iris dataset contains 50 instances from each of these three species and consists of four features namely sepal_length (cm), sepal_width (cm), petal_length (cm), petal_width (cm). We can use Principal Component Analysis (PCA) to transform IRIS dataset into a new feature space with 2 features. Steps We can follow the below given steps to ... Read More

How to transform Sklearn DIGITS dataset to 2 and 3-feature dataset in Python?

Gaurav Leekha
Updated on 04-Oct-2022 08:35:06

486 Views

Sklearn DIGITS dataset has 64 features as each image of the digit is of size 8 by 8 pixels. We can use Principal Component Analysis (PCA) to transform Scikit-learn DIGITS dataset into new feature space with 2 features. Transforming 64 features dataset to 2-feature dataset will be a big reduction in the size of data and we’ll lose some useful information. It will also impact the classification accuracy of ML model. Steps to Transform DIGITS Dataset to 2-feature Dataset We can follow the below given steps to transform DIGITS dataset to 2-feature dataset using PCA − First, import the ... Read More

Advertisements