How to overlap plot in python? - python

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.

Related

Change legend number range in Altair plot

I am trying to plot time series data in a kind of "climate stripes plot" using the package Altair.
The problem is that I do not know how to change the range in the legend to standardise all my plots with the same colour range and numbers in the legend. At the moment, each time I plot something the legend adapts to the range of the data.
I think the problem is with the "domain" property, maybe is not in the correct place ?
Thank you for your help :)
This is the code for the plot :
chart=alt.Chart(source).mark_rect().encode(
x=('day:O'),
y='subasins:N',
color=alt.Color('90%:Q',legend=alt.Legend(title='CH4'), bin=alt.Bin(maxbins=20),
scale=alt.Scale(scheme='blueorange'),domain=[1830,2000])
).properties(width=100).facet(column=alt.Column('month'))
chart.show()
Plots that I get now with different scales in the legend
You're using the right approach with domain, it just needs to be put inside alt.Scale:
scale=alt.Scale(scheme='blueorange', domain=[1830, 2000])
When you're using a bin transform, one way to ensure the scale is consistent is to specify the bin extent:
bin=alt.Bin(maxbins=20, extent=[1830, 2000])

Is it possible to plot multidimensional points in parallel aligned axes with python

I want to plot multidimensional points in a graph. To do so, I want each axis lined up in parallel. So every point becomes a line in this plot. Maybe there is also a special name for this type of graphs/plots? In the figure below, I have sketched a picture of such a plot with exemplarily 4 axes and the point (5, 60, -10, 7.5). It would be fantastic if the axes are scalable seperately.
Does anybody know a plot-package in python which is capable to plot in this way, and how to do it in that library?
I don't know of a straightforward way to do that.
However, I can recommend using Radar Plots, it shows exactly the information you want to show:
https://williamhuster.com/radar-chart-in-python/

Scatter plot and contour plot with same colors

Is it possible to force plt.scatter into the same color levels as plt.contourf and plt.contour? For example, I have code that makes a plot like this:
to make the first subplot, I use
cs=m[0].scatter(xs,ys,c=obsData,cmap=plt.cm.jet)
m.colorbar(cs)
To make the second subplot, I use
cs2=m[1].contourf(x,y,areaData,cmap=cs.cmap)
And for each subsequent subplot, I use
m[ind].contourf(x,y,areaData,cmap=cs.cmap,levels=cs2.levels
where areaData is recalculated within a loop.
My question is, how can I force the first subplot to have the same colors as the other subplots? I am looking for an equivalent to the levels=cs2.levels keyword argument.
As you noted in a comment, your scatter and contour data are not directly related, but you want to display them on the same colormap.
I suggest setting a common colour span that contains both sets of data. Since obsData refers to the scatter points and areaData to the contours, I'd set
vmin,vmax = (fun(np.concatenate([obsData,areaData])) for fun in (np.min,np.max))
to determine the span of the collected data set (obviously, to be generalized for multiple input data sets). These can be passed to scatter and contourf to set the limits of the colour mapping:
cs = m[0].scatter(xs,ys,c=obsData,cmap=plt.cm.viridis,vmin=vmin,vmax=vmax)
cs2 = m[1].contourf(x,y,areaData,cmap=cs.cmap,vmin=vmin,vmax=vmax)
Some manual increase of the span might be in order to obtain a pretty result.
Note that I changed the colormap to viridis. If you really want to fairly represent your data, this should be your first step.

Overlaying subplot on seaborn factorplot

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.

How can I draw inline line labels in matplotlib?

I have the following graph, consisting of several lines:
Now, I would like to label all the lines in the plot. However, using legend() crams all the labels together in a box, which makes the plot somewhat difficult to interpret. What I'd like to to instead is to use inline labels. My ideal output would use labels like the following matplotlib contour plot, but with text labels for lines instead of numbers:
I haven't been able to find out how to do this in the matplotlib documentation. Is there a way to achieve this? If not, what other software could I use to generate this type of plot?
May I suggest another solution to your problem. Since in your case legend overlaps the charts you might just want to move the legend outside of the plot.
Method do move legend outside of plot is described here:
Moving matplotlib legend outside of the axis makes it cutoff by the figure box

Categories

Resources