multiple boxplot in subplots in python - python

I have 18 individual of np.arrays, each containing 30 numbers with similar range (share = True).
I want to create boxplots for all 18 arrays in a subplot of 1 row, 4 columns. Each subplot will contain few sets of arrays.
How do I do this?
when I try it, it looks like this:
This was my trying to put them in one, the red scratch was what I want it to look like

I get this solved!!
Since it's only 1 row,
I should use only
-axes(num)
instead of
-axes(num,0)

Related

Python Subplots Automate nrows and ncolumns

I am writing code that will output subplots for anything between 1 subplot and 20 subplots. The row and column configuration for all 20 different types of plots will be different, (e.g. for 4 subplots, I'll want 2 rows and 2 columns, but for 12 subplots I'll want 3 rows and 4 columns), and instead of typing in the number of rows and columns I want for each different number of subplots, I was wondering if there was a way to automatically generate the nrow and ncolumn values based off of the number of subplots I want in the image. I know there are similar questions to this out there, but I've only seen answers that suggest manually entering in the number of rows and columns you want for each subplot, and haven't seen a way to automate it yet. Thanks in advance for the help!
Maybe try the package grid_strategy? https://github.com/matplotlib/grid-strategy

is possible to create 3 graph in two rows using matplot lib in python?

I want one table in the first row and in the second row two diagrams.
like :
how can I change the size of 1 ?

Seaborn lineplot hue input could not be interpreted

I am trying to plot my dataframe as a lineplot.
The data is 2D movement data of x and y coordinates.
The dataframe has a column which identifies the data of each individual by a unique ID and a column that identifies the test group of the individual and an additional relevant column that shows the timepoints.
index Location_Center_Y unique_id Location_Center_X classifier
0 0 872.044 B21 0.000 ctrl
1 1 868.727 B21 -3.317 ctrl
2 2 864.918 B21 -7.126 ctrl
3 3 866.462 B21 -5.582 ctrl
I do want to display the data of each individual in a lineplot and want the lines to have different colours based on the test group.
Getting each individual as a single track I achieved by plotting the data of each individual at a time.
I tried using the input units='unique_id' but this unfortunately only works for seaborn.scatterplot. When using it with seaborn.lineplot it raises the error
"ValueError: Could not interpret input 'unique_id'"
But whatever, looping works. However I want it coloured by the different groups (classifier column). This should be doable by using the input argument hue='classifier'.
#looping through the individuals
for n in data.cells:
ix=data.tracks[data.tracks['unique_id']==n]
ax=sns.lineplot(ix['Location_Center_X_Zeroed'],
ix['Location_Center_Y_Zeroed'], hue='classifier')
However, again this raises the error
"ValueError: Could not interpret input 'unique_id'".
So I have no idea how to group my plot.
I should get something like this but with only 2 colours
It's hard to be sure since you didn't provide enough data for me to directly try it out, but it seems like this is what you are looking for?
sns.lineplot(data=df, x='Location_Center_X', y='Location_Center_Y',
hue='classifier', units="unique_id", estimator=None)

Plotting N number of Graphs

I have a DataFrame that looks like this:
spot total
date_delivery
2016-06-21 x 20
2016-07-25 x 22
2016-08-14 x 25
2016-09-11 y 16
2016-10-16 y 10
The index of the DataFrame is in a datetime format. I want to create a simple graph for each unique spot that shows the total over time. I am having trouble writing a loop that performs this as well as saves each one. Keep in mind that while there is only 2 actual spots in this DataFrame the real one has many many more.
Append spot to the index, groupby spot and then plot
df.set_index('spot', append=True).groupby(level='spot').plot(kind='bar')
For your example you'll get two bar graphs, one for x, one for y, right below each other (but you can customize that)

How to change axis limits for time in Matplotlib?

I have a data set stored in a Pandas dataframe object, and the first column of the dataframe is a datetime type, which looks like this:
0 2013-09-09 10:35:42.640000
1 2013-09-09 10:35:42.660000
2 2013-09-09 10:35:42.680000
3 2013-09-09 10:35:42.700000
In another column, I have another column called eventno, and that one looks like:
0 0
1 0
2 0
3 0
I am trying to create a scatter plot with Matplotlib, and once I have the scatter plot ready, I would like to change the range in the date axis (x-axis) to focus on certain times in the data. My problem is, I could not find a way to change the range the data will be plotted over in the x axis. I tried this below, but I get a Not implemented for this type error.
plt.figure(figsize=(13,7), dpi=200)
ax.set_xlim(['2013-09-09 10:35:00','2013-09-09 10:36:00'])
scatter(df2['datetime'][df.eventno<11],df2['eventno'][df.eventno<11])
If I comment out the ax.set.xlim line, I get the scatter plot, however with some default x axis range, not even matching my dates.
Do I have to tell matplotlib that my data is of datetime type, as well? If so, then how can I do it? Assuming this part is somehow accomplished, then how can I change the range of my data to be plotted?
Thanks!
PS: I tried uploading the picture, but I got a "Framing not allowed" error. Oh well... It just plots it from Jan 22 1970 to Jan 27 1970. No clue how it comes up with that :)
Try putting ax.set_xlim after the scatter command.

Categories

Resources