I have a plot that graphs multiple datasets against time, over several different generations. A slider controls the generation. The way I'm accomplishing this right now is by making (Number of Generations * Number of Lines) scatter plots in a list that I pass in to plotly.offline.plot. This makes creating the generation slider pretty difficult and full of annoying bugs (like the legend changing order for each generation).
My question is this: Is there some way I can group multiple scatter plots (like with a Figure) and pass in a list of those groups in to plotly.offline.plot?
Related
I am trying to use matplotlib to show some data in a clear way. My current goal is to label the data using two methods: color and shape. The color will be used to represent the data set these specific points come from, while the shape is used to represent whether that example is in category one or two. To visualize this, here is a simple example I drew in PowerPoint:
The reason for doing this instead of simply creating a legend with each specific data set and category stated is I am plotting upwards of 10 data sets, so the legend would remain significantly cleaner and easier to read if color was used for the data sets and shape used for general category (thus the legend would show 10 colors and two shapes, as opposed to 20 different color-shape combinations).
I am currently able to use matplotlib to set the label of the individual data sets by iterating through them and plotting each individually as follows:
import matplotlib.pyplot as plt
ax = plt.figure()
for data in datasets:
scat_plot = ax.scatter(data[x], data[y], label=data[label])
ax.legend()
plt.show()
However, when I attempt to plot the individual shapes and colors and assign them the same label, I am left with plots that do not recognize the two scatter collections as having the same label.
Any suggestions or hints would be greatly appreciated. Thank you.
I am trying to get two different plots as one plot. I will not write down my entire code (is so long), but based on the two small codes below, i get two different time series and I want to put these together in one figure.
My code for the first plot:
plt.figure(figsize=(15,4))
i = plt.plot(july/july.mean(),label='G')
my code for my second plot:
spi3 = pd.read_csv('SPI3.csv',header=0,parse_dates=True)
spi3.plot(y='spi',figsize=(16,4))
Quick dirty fix would be to plot dictionaries at first, only then plot with plt.plot. Also, if you want to plot in the same figure, define figsize only in the first figure you are plotting. (Therefore plt.figure is ommitted completely.)
spi3.plot(y='spi',figsize=(16,4))
plt.plot(july/july.mean(),label='G')
I am automating making reports based on particular locations. Certain graphs contain bar graphs with only one bar and they span the width of the graph. I tried using axes.set_xlim(0, len(data)-1) but ended up with the graph looking like the top one in the attached picture, if there are more than one bars. When I have multiple bars, usually leaving out axes.set_xlim gives a decent graph (last graph in picture). I know using width in the graph will only work is there are two or more bars.
I used len(data) since data is a list and the length would tell me how many bars are going to pop up.
My graph code is within a for loop, so each iteration will have a different length for data
Is there a way to adjust the widths accordingly?
I want to plot boxplots on top of the scattered points like this.
I know I have to bin the data into intervals first but I couldn't find the function that does all of this. Sample x and y data are saved here as .npy.
I would look into using matplotlib. Boxes can be drawn as such:
https://matplotlib.org/gallery/pyplots/boxplot_demo_pyplot.html?highlight=boxplot
and scatter plots can also be drawn as such: https://matplotlib.org/gallery/lines_bars_and_markers/scatter_demo2.html?highlight=scatter
There is a search functionality on their site, along with plenty of documentation on how to utilize their library.
As for your specific question, you can specify zorder when drawing many of the things in matplotlib, and you could use that to define your boxplots to be on top. I believe if no zorder is defined that it draws items in the order they are encountered in your program (so you could draw scatter plots and then box plots and they should appear correctly as in your diagram above!
I have subplots that come in pairs and then are stacked. I have them dynamically build based on how many runs I do (2 subplots side by side per run).
These subplots have titles on top (default position).
What I am running into is that the second pair's title, which resides under the first pair, is over lapping with the x-axis of the first pair.
I have tried tight_layout however it squished my graphs to the point of them being unusable.
I am looking for a way to stack pairs of subplots with enough room inbetween to have titles. Is there any way to add padding in between the stacked pairs. I also tried subplots_adjust(bottom=0.2) but that didn't work either.
I figured this would be a lot easier.