I am plotting 2D contourf, after which I added some contour for some levels.
CS = ax.contour(XX,YY,Z, levels, colors='k')
ax.clabel(CS, inline=True, fontsize=10)
The above simple lines generate the figures below, where the labels are located outside the plot.
While I can fix the (x,y) values with manual, this will not work as generally as I want.
For example, I can try to fix (x) location, e.g. the center of the xlim, and find (y) values for the corresponding contours of each level. But as you can see in the shown figures, it is not general since the 0.100 contour does not have (x) location inside the plot, which is fixed to the center of xlim in this case.
I am pretty sure there is some way to put the labels inside the plot, but it is hard to find.
Any suggestions will be appreciated.
Related
I have a question, I am plotting in python and I put these plots together in Latex. The figure sizes are the same, however, as you can see the plot width and height of the axes of the plot are not the same. Also because figure a has one xlabel (alive or dead), while figure b has two (the numbers range and 'amount of days'.
Anyone has an idea how I can set the width and height of the plot?
I already tried put.figure(figsize(x,y) but that only fixes the figure length, but I need to fix the size within the figure.
Thanks
I am trying to create one plot with one scatter and multiple lineplots.
For the points to be seen well, I need the scatterplot in the front.
However changing the order inside my code doesn't solve this. The
lineplots always cover the scatterplot. Any ideas?
Please help.
Use the zorder parameter when scatterplotting, e.g.
sns.scatterplot(x, y, ax=ax, color='orange', zorder=7)
You may need to adjust the zorder value depending on the number of elements in your plot.
full - clearest image, shows the labels extending out the right of my plot
"zoomed" - highlighting why this is a problem as the plot becomes unreadable when selecting and plotting subset of the x-axis range
I'm working on some data where I have plotted a spectrum and have added vertical lines to specific positions. I have labelled these lines but my problem is that if I want to "zoom in" by decreasing my x axis range, the full list of labels for the vertical lines are still plotted resulting in an unreadable plot.
I iterate through a list of x positions and labels for my vertical lines and plot as follows:
for x_pos, label in zip(list_x_pos, list_label):
plt.axvline(x=x_pos)
plt.text(x_pos, y, str(label), rotation=90)
plt.xlim(2, 5)
So, because my "x values" go > 5 the resulting plot is a tiny figure with a row of the labels extending out from it.
The only solution I can think of is to slice my list_x_pos but this will crate other problems for me so ideally looking to find a way to just show the labels within the range of the plot.
Hope I've made sense!
Thanks,
Olie
You can use plt.text(..., clip_on=True) to force texts outside of the box to not be displayed.
Resize the axes first and then plot the vertical line.
Suppose one has a plot like this, for which the peak is at (x,y) = (0,0.40). The distribution is plotted in blue. Is it possible to edit the color scheme of the distribution plot in such a way that the color is a gradient - the farther from x (or y or independently for both) the more the color changes - like this?
I've searched SO for help with this, but only found solutions in which line segments were different colors. But, I want the color transition to be smooth (like this but not 3-D) instead of rough, and I want the color to depend on its distance from a particular value rather than pre-determined "randomly". A different SO post did something similar (not quite what I want though), but could only do so as a scatter plot, which only works for changing colors based on x-value if the peak is at x=0 - I'd prefer it be generalized. As an example, the further from x=0 the redder the curve gets. Ideally, there's a way to do this with a matplotlib colormap.
I want to project a 3D plot into a 2D plot. Assuming f(x,y) describes my 3D plot, I want to treat y as a parameter and simultaneously plot f(x,0), f(x,2), f(x,4), etc. in one 2D plot. Instead of going for different line/point styles and colors with a legend in a corner, I'd like to make each plot in the same style and place a label next to each individual line.
Is this even possible in gnuplot or would I have to fall back on something more complex?
I had a similar question recently. There is an option in the development version of gnuplot (4.7.0) that does this. You can change the position of line titles to be at the end/beginning of the line itself. If your plot looks like I imagine (sort of a contour plot) this may be what you want:
plot f(x,y) title 'f(x,y)' at end
Otherwise you may have to specify the labels and their positions manually:
help set label
for more info.