My question is simple.Hot to make the two scatter plot in one figure?
There is error if I just write the two pl.scatter one by one.
a,b,c=np.loadtxt('mydata',usecols=(0,1,2),delimiter=",",unpack=True)
pl.scatter(a,b,color='g',s=0.5,'b')
pl.scatter(b,c,'r')
The other question is how to use the left y and right y axis together,say,the first scatter plot use the left y axis and,the second scatter plot use the right y axis.
You can use ax.twinx() to create a second y-axis that shares the same x-axis
ax1 = pl.axes()
ax2 = ax1.twinx()
ax1.scatter(a,b,color='g',s=0.5)
ax2.scatter(b,c,color='r')
The error you were seeing is probably because you have a non-keyword argument ('b') after a keyword argument (color='r').
Related
Can you plot a histogram in matplotlib so that it appears upside down, i.e. the base of the histogram is along the top axis and it "hangs" down? Or, alternatively, if plotting with orientation='horizontal', so that the base of the histogram is on the right hand axis?
Yes, use invert_yaxis:
df = pd.DataFrame({'a':[1,2,3,1,2,2,2],
'b':[1,1,1,3,2,2,2]})
ax = df.plot.hist()
ax.invert_yaxis()
Output:
I am plotting three different lines in the same figure using matplotlib in pylab. I want to plot a "y" axis on the right, and two on the left. Now I can plot one on the right and one on the left:
pylab.subplot(311)
pylab.annotate('(a)', xy=(0.03, 1e17), xycoords='data', color='k')
pylab.grid(True)
noxticks()
pylab.semilogy(t[:], pht[:])
pylab.ylabel('Total photons')
pylab.twinx()
pylab.semilogy(t[:], pht2[:])
pylab.ylabel('Received photons 1')
I want to add another y axis on the left to plot also pht3, but I cannot. How could I do that?
Thank you!
I'm quite new to python and I need some help. I would like to plot errorbars equivalent to 1sigma standard deviations on my plot as the 16th and 84th percentile values of the distributions. I tried with (using matplotlib):
err=np.std(x)
but it just gives me the standard deviations.
Thanks.
If you want vertical error bars
ax = plt.gca()
ax.errorbar(x, y, yerr=np.vstack([error_low, error_high]))
plt.draw()
where error_low and error_high are 1D sequences of the same length an x and y. The error bars are drawn at y[i] - error_low[i] and y[i] + error_high[i].
matplotlib just draws what you tell it to, it is your job to provide the semantics.
errorbar documentation
Is there any way to create a plot like the one in figure below, having an axis scale of 1:1. By 1:1 I mean that if two ticks with values 100-200 have a distance on screen of 2cm on the x axis, it should be the same on the y axis. Instead as you can see in the figure, ticks on the x axis are much larger.
ax.set_aspect('equal') after the fact for each axis ax = fig.add_subplot(111, aspect='equal') when you generate the axes. example/doc
Can I have both twinx and twiny together (i.e. something like twinxy)?
I want to put a CDF on a bar plot where the X axis of the bar plot is in log-scale. I cannot make the Ys together, because the bar plot y range is very large comparing [0,1] for CDF.
Any ideas?
Thanks,
If I understand your question right, you want to plot two things on the same axes with no shared axis. There is probably a better way to do this, but you can stack twinx (doc) and twiny (doc) as such
ax # your first axes
ax_new = ax.twinx().twiny()
Which will give you tick marks on all sides of the plot. ax will plot against the bottom and left, ax_new will plot against the top and right.