Here's the result of scatter plot using Matplotlib
And now here's the result of calling scatter plot using Pandas
Is there bug in Pandas scatter function or is it supposed to work like this?
I think the grey area you see is the boundary of each point. Use the argument edgecolors='none' or edgecolors='black' to get the same result as you get with matplotlib (see also http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter)
Related
I have a xarray dataset clip_ds and have visualised the data array using plot. Now, I want to add a country boundary using Basemap's drawcountries(). Apparently, there is something wrong with the extent I am using in basemap (I guess), but both the country border and the data plot won't show up together. I have tried interchanging the position of clip_ds.pr[0].plot() before and after I create basemap, and it gives me two different results as shown below:
Xarray PLOT BEFORE BASEMAP (Note that the colorbar from xarray plot is still there)
Xarray PLOT AFTER BASEMAP (Notice difference from 3, height of the plot shrinks here and the tick labels disappears, probably overlapped by basemap.)
Xarray plot only
Loading seperate shapefile using map.readshapefile also gives same kind of problem. I know there might be a way around this using cartopy, but I like the Basemap functionalities and would like to know if there is any solution to this.
map=Basemap(projection='merc',
resolution='l',
llcrnrlon=clip_ds.lon[0],
llcrnrlat=clip_ds.lat[0],
urcrnrlon=clip_ds.lon[-1],
urcrnrlat=clip_ds.lat[-1])
map.drawcountries()
clip_ds.pr[0].plot()
plt.show()
I'm trying to get my seaborn plot to look something like this:
If I use lmplot with the z-axis for the hue, I get this:
The lmplot in the picture is basically what I want, but I need the colorbar on the right side instead of the actual values.
I tried to do this with a heatmap, but the data plot was worse that way due to the large gaps between samples.
Thanks for any help!
You should use plt.scatter. The hue parameter in lmplot only accepts categorical variables.
Given below is the code for plotting points using pyplot.
x1=300+p[k]*math.cos(val[thetaval])
y1=300+p[k]*math.sin(val[thetaval])
plt.plot(x1,y1,'k.')
The plotting is working fine, the problem is, if I want to plot it as a point I am specifying the dot in 'k.' inside the plot function. The output is something like:
The width of the black line/curve that I am plotting is much more that needed. How to reduce it?
It seems that you are not plotting a line but a series of small points. Maybe if you try setting the markersize argument of the plot function could work.
Looking into the documentation of plot() you can find "linewidth"
So use:
plt.plot(x1,y1,'k.', linewidth=0.1)
I need to return both a histogram and a scatterplot in one function using matplotlib, but when I try to create the histogram after creating the scatterplot, it appears that the scatterplot gets overridden. Just wondering if anyone has any advice on this issue? Is there a way to return two plots at once if they share an x-axis?
For instance, there is paragraph included in this link http://matplotlib.org/users/pyplot_tutorial.html about how to have 2 subplots. But I'm not sure how to do that with plt.hist() and plt.plot().
Since the histogram fills the bars it is probably better to do it first then the scatter plot.
Im new to Python and Pandas but have a CSV file with multiple columns that I have read in to a dataframe. I would like to plot a scatter plot of x=Index and y='data'. Where the index is Index of the dataframe and is a date.
Thanks heaps
Jason
You can use plot_date:
plot_date(df.index, df.data)
Whilst, I guess technically not a scatter plot, you can use the pandas.plot function with point markers drawn on and no lines.
df.plot(marker='o', linewidth=0)
This then allows us to use all of the convenient pandas functionality you desire. e.g. plot two series and different scales, using a single function,
df.plot(marker='o', linewidth=0, secondary_y='y2')
The downside to this is that you lose some of the scatter functionality such as shading and sizing the markers differently.
Still, if your aim is a quick scatter plot, this might be the easiest route.