I making this plot with custom bins, so some of them are empty. Eventually I want to remove the bars and keep only the line. But I need the line to simply start at the first point (rather than on the x axis) and connect with all the others. How do I prevent those vertical lines?
Related
I have a data which I am trying to plot. However when I call plot function, I get a weird line. How can I get rid of this thing and why does it occur ?
The plot function draws lines between points. If there is a "weird" line, then it means you are providing two consecutive points that form that line
What I am trying to do, is visualize data with 3 independent variables. So I made a grid of plots using subplots, where the x axis is the same everywhere. The y axis, on the other hand, depends on the position on the grid. In the x-direction you have another independent variable and the same in the y-direction. So what I would like to do, is to have some kind of overarching axis where the ticks and the numbers are right underneath (for the axis below) each column, so you know which value of this particular variable the column corresponds to. I can't seem to find any info on how to do this with matplotlib.
fig,ax=plt.subplots(5,3,sharex='col',sharey='row',figsize=(6,10))
for inrs in range(nrs):
for inrg in range(nrg):
n=int(neti[inrs,inrg])
ax[inrs,inrg].plot(xet[inrs,inrg,1:n],dphid[inrs,inrg,1:n],color='green')
plt.show()
I found a way to do this. I don't think there is any "regular" way of doing this. What I did was to use the command
ax=fig.add_axes([0.25,0.05,0.55,0.000001])
for the x axis. Here, (0.25,0.05) is the position (x0,y0), and (0.55,0.000001) is the (width,height) of the figure. The exact numbers depend on the plots you have. What you are doing in essence, is creating an additional very thin plot, where only the x-axis will be visible. To disable the y-axis:
ax.axes.get_yaxis().set_visible(False)
Then you can use the commands:
ax.set_xlabel("xlabel")
ax.set_xlim([])
ax.set_xticks([])
to complete the axis. For the y-axis, it's the same thing. In my case, for the x-axis, the ticks are not evenly spaced. To fix this, I simply created another such plot within the previously existing one to put a particular tick where I needed it to be.
I have a program to plot some values.
I want to change some values in my script and plot it overlap.
How can i do it?
Thanks
plot in python
You just do it again.
For instance, if you did:
plt.scatter(x,y,z, etc)
plt.scatter(x1,y1,z1, etc)
You'd get a plot with both of those.
You may want to specify the colors of the second one because otherwise, it will start over with the first color it would use.
I regularly plot a contour over a contourf that way.
I'm creating a plot with factorplot and then trying to add a subplot on top of each box. How can I get the x-axis locations of each individual box in the factor plot to put another line on top?
Maybe there's a way to get all the x-axis values of each box plot on the axes?
Here's my basic factor plot:
I want to add 1 subplot (the circle) in the middle of each box plot. However, I cannot figure out how to get the x-value of each box to properly space the points.
I see a lot of code for positions and offsets in the seaborn source that lays these out. However, I'm wondering if there is a more straight-forward method to get this information or at least approximate it.
As per #mwaskom's comments, you can use sns.stripplot() (and now also sns.swarmplot()) to include your data points with a data summary plot such as a box or violinplot.
![Left: Data from 2000-2040, Right: Data from 2001-2039][2]
Is there a way I can manually edit the bounds of my plot? When my x axis data runs from 2000 to 2040 matplotlib rearranges the plot such that a lot of white-space is produced on both the left and right sides of the plot, as in the left picture. However when I change my x axis data from 2001 to 2039 there is no whitespace as in the right picture. I suspect this happens because of how matplotlib automatically arranges the ticks. The question is how can the x-ticks be manipulated manually to avoid unnecessary whitespace? Any ideas?
You can use the various pyplot functions called xlim, ylim (to set the limits of the axes), xticks, yticks (to set the tick positions) etc. Read the documentation.