Plt.title('How To Highlight Data with Color and Text \n with matplotlib in Python?',size=14) ![]() Let us repeat the same code as above to highlight the data points using using a subsetted dataframe. For example, it will be good to know the countries of outlier data points that we colored. In the above plot, it may better to actually plot more information about the outliers. How To Highlight Data Points with Color Python? How to Highlight Data Points with Color and Text in Python? Now we have highlighted the select data points, in this case outliers, in red color on a scatter plot. Plt.savefig('How_To_Highlight_Data_Points_with_Color_Python.png', dpi=150) Plt.scatter(df.lifeExp, df.gdpPercap, color="red") ![]() ![]() We also specify the color we want, here we specify the color to be red. We can again use scatter() function, but this time with the data from the subsetted dataframe df. We have already subsetted the data points in a new dataframe “df”. Now we can add new layer of scatter plot, but this time only with the specific data points that we want to highlight. Plt.title('How To Highlight Data Points with colors \n in Python with matplotlib?',size=16) Plt.scatter(gapminder.lifeExp, gapminder.gdpPercap, alpha=0.5) Here we have just changed the title of the plot. To start with we will first make scatter plot exactly as before between the two variables. Now that we have the data points that we want to highlight in a specific color, we are ready to write code highlight them with matplotlib in Python. We can use Pandas’ query() function to subset the interesting data points as follows.ĭf = gapminder.query('gdpPercap >=50000
0 Comments
Leave a Reply. |