Note I don’t set the edgecolor here, but if you want to make the edges semitransparent as well you could do edgecolor=(0.0, 0.0, 0.0, 0.5), where the last number of is the alpha transparency tuner. This allows you to further visualize the density, but then makes it a bit harder to see individual points – if you started from here you might miss that outlier in the upper right. Another quick trick is to make the points smaller and up the transparency by setting alpha to a lower value. So that is better, but we still have quite a bit of overplotting going on. Plt.savefig('Scatter02.png', dpi=500, bbox_inches='tight') #Making points have an outline and interior fillĪx.scatter(crime_dat, crime_dat, All of this action is going on in the ax.scatter call, all of the other lines are the same. Here I also make the interior fill slightly transparent. I think a better default for scatterplots is to plot points with an outline. You can see here the default point markers, just solid blue filled circles with no outline, when you get a very dense scatterplot just looks like a solid blob. Plt.savefig('Scatter01.png', dpi=500, bbox_inches='tight') Then I set the axis grid lines to be below my points (is there a way to set this as a default?), and then I set my X and Y axis labels to be nicer than the default names. I don’t have a good reason for using one or the other. You could also instead of starting from the matplotlib objects start from the pandas dataframe methods (as I did in my prior histogram post). After defining my figure and axis objects, I add on the ax.scatter by pointing the x and y’s to my pandas dataframe columns, here Burglary and Robbery rates per 100k. My_dir = r'C:\Users\andre\OneDrive\Desktop\big_scatter'Ĭrime_dat = pd.read_csv('Rural_appcrime_long.csv')įirst, lets start from the base scatterplot. I technically do not use numpy in this script, but soon as I take it out I’m guaranteed to need to use np. So first for the upfront junk, I load my libraries, change my directory, update my plot theme, and then load my data into a dataframe crime_dat. Here you can download the dataset and the python script to follow along. customizing a template, adding legends, etc.)įor this post, I am going to use the same data I illustrated with SPSS previously, a set of crime rates in Appalachian counties. Notes on making matplotlib and seaborn charts (e.g.I made some ugly scatterplots for a presentation the other day, and figured it would be time to spend alittle time making some notes on making them a bit nicer.įor prior python graphing post examples, I have: My current workplace is a python shop though, so I am figuring it out all over for some of these things in python. Many of my programming tips, like my notes for making Leaflet maps in R or margins plots in Stata, I’ve just accumulated doing projects over the years.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |