![]() We get a nice colored bubble plot made with matplotlib. Plt.title("Bubble Plot with Colors: Matplotlib", size=18) Here, Colors is the quantitative variable that we created when we constructed the dataframe. And we use the argument c=”Colors” to color the bubble by a variable. The scatter() function has the argument “c” for specifying colors. Let us color the bubbles differently using another variable in the bubble plot. Simple Bubble Plot in Python with Matplotlib Color Bubble Plot By Variable in Python Step 1: Import all the necessary libraries The first step is to import matplotlib, NumPy, and other required libraries for our tutorial. Inside the scatter () function, s is the size of point in scatter plot. We import NumPy to make use of its randn () function, which returns samples from the standard normal distribution (mean of 0, standard deviation of 1). So it’s best that you should also code there for more understanding. Here in this tutorial, we will make use of Matplotlib's scatter () function to generate scatter plot. First, we pass the x-axis variable, then the y-axis one. We have also added transparency to the bubbles in the bubble plot using alpha=0.5. Steps to Create a Scatter Plot in Matplotlib Please note that I am using Jupyter notebook for implementing Matplotlib Scatter Example. Its very easy to do in matplotlib use the plt.scatter() function. By default, Matplotlib makes the bubble color as blue. ![]() We can see that the points in the scatter plots are bubbles now based on the value of size variable. Plt.title("Bubble Plot with Matplotlib", size=18) To make bubble plot, we need to specify size argument “s” for size of the data points. Using Matplotlib, we can make bubble plot in Python using the scatter() function. 2 Color Bubble Plot By Variable in Python.Our customized scatter plot looks like this. Plt.title("Scatter Plot with Matplotlib", size=18) We also add a title to the scatter plot using plt.title(). Here we customize the axis labels and their size using xlabel and ylabel functions. The x and y-axis label sizes are smaller by default, when we make scatter plot using scatter function(). Matplotlib is easy to use and an amazing visualizing library in Python. Respective values from the s size list shall be applied to the markers drawn at points specified by x and y. To specify size to each of the markers, pass a list for named parameter s to scatter () function. Let us first make a simple scatter plot with Matplotlib using scatter() function. Matplotlib Scatter Plot Basic Example Now, let us specify size to each of the points. Here we construct dataframe from NumPy arrays using Pandas’ DataFrame function and providing the variables as a dictionary. Let us store the simulated data in a Pandas dataframe.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |