I produced a histogram which looks something like this:
Code that I used to produce this plot:
sns.countplot(table.column_name)
As you can notice, the entire histogram gets clustered at the left end due to uneven distribution of data.
How do I zoom in at the left end?
One way that I tried and it gave me a marginally better result was :
plt.xlim(0,25)
Is there a better way to do this?
Looks like the data would be better viewed on a logarithmic scale. On your matplotlib plot axis, ax, use:
ax.set_yscale('log')
Related
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 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 Posted this question about 3D plots of data frames:
3D plot of 2d Pandas data frame
and the user referred me very very helfully to this:
Plotting Pandas Crosstab Dataframe into 3D bar chart
It use useful and the code worked in principle, but it lookes like a mess (see image below) for several reasons:
I have huge number of values to plot (470 or so, along the y-axis) so perhaps a bar chart is not the best way (I am going for a histogram kind of look, so I assumed very narrow bars would be suitable)
my counts (z axis) do not give almost any information, because the differences I need to see are from 100 to the max value
how can I make the 3D plot that shows up interactive? (being able to rotate etc) - I have seen it done in blogs/videos but sure if it's something on Tools -> Preferences that I can't find
So re: the second issue, simple enough, I tried to just change the limits of the zbar as I would for a 2D Plot, by incorporating:
ax.set_zlim([110,150])
just before the axis labels, but obviously this is the wrong way:
SO do I have to limit the values from the original data set (i.e. filter out <110), or is there a way to do this from the plot?
I've drawn a plot of 20 points on matplotlib
However, applying a '-o' parameter on the plot causes the plots to be connected in a weird order.
I would like it connected along the x axis (lowest x to highest x)
It currently looks like this
This is what it looks like with '-o'
Is there a way to force matplotlib to plot in increasing order of x values?
Yes.
Sort the points in increasing order of x-coordinates before giving those points to matplotlib, which simply connects the points in the order you give them to matplotlib.
(We could help you more if you show us the code, perhaps simplified, that gave you that bad example plot.)
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)?