When I draw a picture using plot in pandas timeseries. I find a parameter named logy. I can't make sure how it works. The documents just say
Use log scaling on y axis
But I try figure it out and test log,log2...on y value.These values are different from the value which in the drawing window. So how plot(logy=True) works?
Related
I want to plot a PDF function given data which follows a normal distribution. Mainly I followed this link.
Now, if I am working on the data created like on that website (x=np.linspace()) and I plot it with either seaborn.lineplot() or matplotlib.pyplot.plot(), I get a normal curve as shown on the website linked above. But when I do this with my own data (which I believe is normal, but with a lot more data points) instead of initializing it with np.linspace I get a clear normal curve with seaborn's lineplot and a messy normal curve with matplotlib's plot function.
I have tried to look for default arguments on both functions but couldn't find any (except estimator) which would cause this behavior. The estimator argument of Seaborn's lineplot was the only argument that looked like it could do something like this but setting it to None did not make any difference (and it kind of makes sense I think since the y value is always same for a specific x so averaging out will produce the same value).
I used to think both functions are the same, but then why do they have different output?
The Seaborn lineplot function has the default parameter sort=True.
So unless you tell it not to, it'll order the data for you. This is not something which pyplot.plot() does, instead it'll draw lines between the points in the order provided.
If you want to order the data before plotting it using Pyplot, there's a good solution for how to do that.
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])
I am using Python's matplotlib.pyplot.contourf to create a contour plot of my data with a color bar. I have done this successfully countless times, even with other layers of the same variable. However, when the values get small (on the order of 1E-12), parts of the contour show up white. The white color does not show up in the color bar either. Does anyone know what causes this and how to fix this? The faulty contour is attached below.
a1 = plt.contourf(np.linspace(1,24,24),np.linspace(1,20,20),np.transpose(data[:,:,15]))
plt.colorbar(a1)
plt.show()
tl;dr
Given the new information, matplotlib couldn't set the right number of levels (see parameters in the documentation) for your data leaving data unplotted. To fix that you need to tell matplotlib to extend the limits with either plt.contourf(..., extend="max") or plt.contourf(..., extend="both")
Extensive answer
There are a few reasons why contourf() is showing white zones with a colormap that doesn't include white.
NaN values
NaN values are never plotted.
Masked data
If you mask data before plotting, it won't appear in the plot. But you should know if you masked your data.
Although, you may have unnoticed mask your data if you use something like Tick locator = LogLocator().
Matplotlib couldn't set the right levels for your data
Sometimes matplotlib doesn't set the right levels, leaving some of your data without plotting.
To fix that you can user plt.contourf(..., extend=EXTENDS) where EXTENDS can be "neither", "both", "min", "max"
Coarse grid
contourf plots whitespace over finite data. Past answers do not correct
One remark, white section in the plot can also occur if the X and Y vectors data points are not equally spaced. In that case best to use function tricontourf().
I was facing the same problem recently, when there was data available even higher/lower than the levels I have set. So, the plt.contourf fills the contours exclusively given by you, and it neglects any other higher or lower values present in your data.
I solved this by adding a key word argument extend="both", which for your case would be something like this:
a1 = plt.contourf(np.linspace(1,24,24),np.linspace(1,20,20),np.transpose(data[:,:,15]), extend="both")
or in general form:
a1 = plt.contourf(x,y,variable[:,:,15],extend="both")
By doing this, you're instructing the module to plot the higher(/lower) values according to the highest(/lowest) filled contour.
If you want only to extend in the lower or higher range, you can change the keyword argument to
extend="min" or extend ="max"
I have one question for plotly x and y axes setting.
It's possible to autorange the axis only the first time based on all input data and then turn off rescaling while manipulating the data input (in the legend)?
https://plot.ly/python/reference/#layout-xaxis-type
From documentation: 'autorange' default: True
Determines whether or not the range of this axis is computed in relation to the input data.
I need autorange only to be done first time and then it should behave like False. I need it so I can make evaluations relative to the whole dataset.
Maybe it can be done another way, not by manipulating autorange but that's why I'm asking.
MY EXAMPLE:
Imagine you have visualization like this. I have labeled many groups so that I can turn them off/on by plotly functionality. But the problem for me is that it is rescaling everytime based on the input data (only the ones which are 'turned on').
This is after I isolate the GROUP 1. But I want the same x-axis and y-axis as I had before (which was 'autoranged' when I started the visualization).
Thanks for your help!
What I'm trying to do is make an interactive scatter plot where I can control which columns of a DataFrame are on X and Y axes and then select a subset of data using lasso or something similar. Because of the dataset size I have to use datashader.
I tried to declare the DynamicMap as:
dmap = hv.DynamicMap(selector.make_view, kdims=[], streams=[selector, RangeX(), RangeY(), Stream.define('Next')()])
and have a custom callback on the lasso which would select desired rows of data, create the visual representation and update the plot with dmap.event().
So that doesn't seem to work. If I select something, the plot gets updated only when I pan or zoom or change axes selection. VIDEO
If I leave only Stream.define('Next')():
dmap = hv.DynamicMap(selector.make_view, kdims=[], streams=[Stream.define('Next')()])
then lasso updates the plot, but I loose everything else including the ability to zoom. VIDEO
I hope this question makes sense. If needed, I've pushed the notebook here.