Change marker border color in Plotly – Python
In this article, we are going to discuss how to change marker border color using plotly module in Python.
This module can be installed using the below command:
pip install plotly
In this article, we are going to change the maker border color with the help of plotly.express.scatter.update_traces() and plotly.express.scatter_3d.update_traces()() methods.
- Import the plotly and pandas library.
- First, we have to load the dataset on which we are plotting our graph with the help of the pandas library.
- For plotting the graph we will use plotly.scatter() for scatter plot and put it in the variable let name as fig
- Then we use fig.update_traces function which is having marker property from which we can change the borders of the marker.
We are going to use the below iris dataset in various examples:
Example 1: Plotting default scatter plot on iris dataset.
Plotting scatter plot on iris dataset and changing marker border color.
In the above code, we had used update_traces() function in that we had given marker attribute for creating the borders in that attribute we had passed the dictionary in which we had passes size=10 for giving the size to the circles, whereas in line we had passed the dictionary in which we had passes width and color, width refers to the width of the border and color refers to the color of the border.
Example 3: Plotting default scatter_3d plot on iris dataset.
Example 4: Plotting scatter_3d plot on iris dataset with marker border color.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course