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])
Related
Is there any way to decrease the density of data labels in Matplotlib? Right now, it looks like this.
This is my code :
countries_list.insert(0, "(0,0)")
arrowprops = dict(arrowstyle='<-', color='blue', linewidth=1, mutation_scale=10)
for i, txt in enumerate(countries_list):
ax.annotate(string.capwords(txt), (x_list[i], y_list[i]), arrowprops = arrowprops)
Thanks.
Edit: I'm thinking more on the side of like is there maybe an automatic option to automatically rearrange the arrows the point to different locations around the plot to make the labels more readable?
so I don't think there is really much you can do as far as adjusting the text size, since you would need to make it a tiny unreadable font to have each word be separate. I think what you are going to want to do is change the scale of your y axis. Right now you have a linear scale on your y axis with a very nonlinear distribution of your data, hence why you have a ton of data points squished near the bottom.
For your x axis set it with something like the following:
ax.set_yscale('log')
check out more about axes and scaling on their website:
enter link description here
Also just found this, which will probably produce a much nicer looking plot than log scaling, especially since I dont know what kind of distribution we are looking at with your data.
enter link description here
You can use that to scale your y axis relative to your dataset and extreme values.
I am using the pandas plot facilities, to plot a bar plot:
spy_price_data.iloc[40:,1].plot(kind='bar')
The bar data is plotted correctly, but the figure contains weird artefacts in the form of additional horizontal bars below the actual figure:
What could be the problem here?
The 'weird artefacts' are your ticklabels. You can even (almost) read them at the end:
The last value seems to say something like 2018-08-19 20:00:00.
To make the plot more readable, take a look at the answer from ImportanceOfBeingErnest to the question Matplotlib: How to increase space between tickmarks (or reduce number of tickmarks)?
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.
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