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)
Related
I've made the following scatterplot. I have an outlier on the positive side of the graph and also the negative end of the graph.
I think normally if I were plotting this using matplotlib.axes.Axes.plot I could use clip_on
But since this was graphed using matplotlib.pyplot.scatter there is no clipping parameter. Do I basically have to adjust the data somehow? Or is there a matplotlib way of doing this?
I am using Jupyter-notebook with python 3.6.2 and matplotlib to plot some data.
When I plot my data, I want to add a legend to the plot (basically to know which line is which)
However calling plt.legend takes a lot of time (almost as much as the plot itself, which to my understanding should just be instant).
Minimal toy problem that reproduces the issue:
import numpy as np
import matplotlib.pyplot as plt
# Toy useless data (one milion x 4)
my_data = np.random.rand(1000000,4)
plt.plot(my_data)
#plt.legend(['A','C','G','T'])
plt.show()
The data here is just random and useless, but it reproduces my problem:
If I uncomment the plt.legend line, the run takes almost double the time
Why? Shouldn't the legend just look at the plot, see that 4 plots have been made, and draw a box assigning each color to the corresponding string?
Why is a simple legend taking so much time?
Am I missing something?
Replicating the answer by #bnaecker, such that this question is answered:
By default, the legend will be placed in the "best" location, which requires computing how many points from each line are inside a potential legend box. If there are many points, this can take a while. Drawing is much faster when specifying a location other than "best", e.g. plt.legend(loc=3).
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)
I am making a scatter plot by plotting every point one after another in a loop :
for i in range(len(lon_buoy_2)):
m.scatter(x[i],y[i],20.,marker='o',lw=0., c=IO_buoy_map_log[i],cmap=cm, vmin=-3., vmax = 0.)
Therefore, when I try to create the colorbar, it can't since the points I plot are not in an array. I tried plotting it not in a loop, but it fails and this is the easiest way to get the plot I want.
What would be a method to get a colorbar?
Thanks!
Doing it not in a loop works fine. Thanks.
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.