I'm trying to make a 5x2 grid of 9 subplots and where the tenth subplot should be placed , I put the legend. To make this I get from the last subplot the legend handle (with ax.get_legend_handle()) and then I do:
ax = fig10.add_subplot(gs0[N_rows-1,N_cols-1])
ax.axis("off")
#h and l are the handles and the labels
ax.legend(h,l, borderaxespad=0, fontsize=50, title_fontsize=15)
The problem is that the legend doesn't occupy the whole figure and if I increase too much the font size of the labels, then it will generate an extra space between subplots. For that reason I want a way to set the size according to the height or the width of the current axis.
Related
I want to create two plots, with the second plot generally being about 1/2 or less the size of the main plot. However, when trying to do this with one row and two columns I get an error
fig, axs=plt.subplots(1,2, figsize=(12,10), gridspec_kw={'height_ratios': [2,1],
'width_ratios':[3,1]})
(ValueError: Expected the given number of height ratios to match the number of rows of the grid).
If I only put in one argument in the list for height ratios then I get two plots that are of the same size.
fig, axs=plt.subplots(1,2, figsize=(12,10), gridspec_kw={'height_ratios': [3],
'width_ratios':[3,1]})
That plot is shown below. How can I make the plot on the right half the size of the one on the left, while placing it in the bottom right (not top right)?
The trick here is that height_ratios depends on the number of rows. A ratio is a relationship between 2 things so you cannot introduce a ratio between height subplots if there is only one row (aka one 'height' for the subplots) - no matter how many columns there are. However, you can trick plt.subplots using fig.add_gridspec to introduce more rows and columns but never call on them. Here is how you can go about it:
import matplotlib.pyplot as plt
if __name__ == "__main__":
fig = plt.figure(figsize=(12, 10))
gs = fig.add_gridspec(nrows=2, ncols=2, width_ratios=[3, 1])
fig.suptitle('An overall title')
# Add left subplot
# gs[top and bottom rows, first column (the 'left' subplot))]
ax_left = fig.add_subplot(gs[:, 0])
ax_left.set_xlabel("Left X label")
ax_left.set_ylabel("Left Y label")
# Add bottom right subplot - gs[bottom row, last column (the 'left' subplot)]
# We do not add the upper right subplot
ax_right_bottom = fig.add_subplot(gs[-1, -1])
ax_right_bottom.set_xlabel("Right Bottom X label")
ax_right_bottom.set_ylabel("Right Bottom Y label")
plt.tight_layout()
plt.show()
If you wanted to make the bottom right subplot smaller or bigger in relation to the left subplot, now you could use height_ratios because now there are two rows and you can implement a ratio.
You can read more about it in Arranging multiple Axes in a Figure - it's full of useful tips for wrangling axes and subplots. Cheers!
I want to label the vertical line which is drawn in gnuplot using the set arrow command, at the top border. How can this be done? For e.g. I have drawn a vertical line at x=-3.8, in the attached image. I want to place the label at the top border at the point where this vertical line meets the top border of the plot..
Is it a best practice to label the vertical lines in this manner? I choose this way because in the plot near the point where the vertical line meets the x-axis, there is already a number. So I had no choice other than placing the label at the top border.
Please check the manual or in the gnuplot console type help label. You can set a label to certain coordinates with offset.
reset session
xPos = -3.8
set arrow 1 at xPos, graph 0 to xPos, graph 1 nohead lc "red" dt 4
set label 1 at xPos, graph 1 "myLabel" offset 0.5,-0.7
plot sin(x)
I have a graph in Excel like below. For the X-axis, the distance between 50 and 100 is the same as that between 100 and 200. Can I ask if I can set it based on the number? That is, the distance between 50 and 100, is half of that between 100 and 200.
Perhaps you can use a scatter plot rather than a line chart. The result looks something like this:
To generate the plot, I selected the whole data block and did Insert > Scatter with the subtype consisting of markers with straight-line segments. I don't know of any way to not show horizontal labels at 50, 100, 200 without doing things like 150, but at least the spacing is right. Obviously, the size, style, and color of the markers and lines are easy to tweak, as is the number and spacing of the horizontal grid lines.
1-How can I rotate my plot so y would be the new x axis and vice versa?
2- Change the maximum value of y axis from 60 to 100.
The plot is created by this script in the terminal :
set palette grey
plot 'color_map.dat' matrix with image
You can exchange the x and y axes with the using modifier. (Just like for ordinary plots, except that for matrix data, columns 1 and 2 are not in your data file, but are inferred.)
plot 'color_map.dat' matrix using 2:1:3 with image
If you actually just want to change the maximum value on the y (new x) axis, you would use set xrange[:100]. But it sounds like you might actually want to scale the data itself, in which case you could use
plot 'color_map.dat' matrix using ($2/60.*100):1:3 with image
Try help plot matrix for more details.
I've created horizontal bar chart with category axis (Y axis). After adding more and more categories to Y axis, height of each horizontal bar is shrinked to zero size.
Here we can see bars with height of 2px, but I want to have at least 6px.
How to restrict height of each bar on the chart?
And how to force chart to request more space if bars for all categories are not fitted in plot area?
Each time you add a new category, increase the minHeight property of the chart.