Seaborn: Plot scatterplot over lineplot in same plot - python-3.x

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.

Related

Python contour clabel created outside the plot

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.

show dates in xticks only where value exist in plot chart and hide unnecessary interpolated xtick labels [duplicate]

Could someone please guide me on how should I make sure that all ticks (or maybe a better way to specify will be to say all elements in the list passed to plot function) are displayed on the x axis when using matplotlib to plot graphs?
plt.plot(xValues, meanWeekdayArrivalCounts, 'k-')
I want all the values in the list xValues to show up on the graph. By default, only, 0, 10, 20, 30, 40, 50 show up.
Simply add plt.xticks(xValues) to your code. Given the number of points in your graph, the labels might clutter.
You could display them as minor ticks if you set them on the axes object with ax.set_xticks(xValues, minor=True).
use this.
fig = plt.figure(figsize=(10,8))
plt.xticks(np.arange(min(x), max(x)+1, 1.0))
I wanted to show all the years in my graph so I did
plt.xticks(list(table_05.anio.unique()))

How to add legend for ** data.set_index ** in Python?

I have plotted this graph but do not know how to add legend and how to change color/shape of the graph.
Does anyone know how to do?
Thank you
Here are the codes and graphs that I have achieved
In the .plot() method, you can pass label and color (as well as a host of other things) as arguments. Color immediately uses the color you specify, but for the label to show up you also need to call plt.legend().
Example:
df["Some Data"].plot(color="green", label="This is some data")
plt.legend()
plt.show()

gnuplot print legend directly next to individual graphs

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.

Draw axis thru x=0 and y=0

I have a set of data that I'm plotting as a scatter graph which has both positive and negative values on both axis. When I plot this in Flot, the axis are draw at the bottom and the left by default. Is there a way to make it draw the axis through the center of the graph? #X=0 and Y=0?
In other words, instead of this:
I want something like this:
That isn't possible in the default flot. I'm sure it could be hacked in if you wanted to dig into the source, but flot by itself only supports left/right for the y-axis, and top/bottom for the x-axis.
In case anybody else comes across the same need, I created a plugin for Flot and put it here:
https://github.com/burlandm/Flot-Origin-Axis
It does what I need, but I won't make any promises that it'll fit your particular scenario. If I have time, I might try and update it to cover more scenarios.

Resources