legend-properties

Manually set legend colors

Manually set legend colors Question: I try to plot the following line plot, but I have difficulties to manually set legend colors. Currently the legend colors did not match the line colors. Any help would be very helpful. Thank you. import random import matplotlib.pyplot as plt random.seed(10) data=[(i, i+random.randint(1,20), random.choice(list("ABC"))) for i in range(2000,2025)] plt.figure(figsize=(14,8)) …

Total answers: 3

Seaborn ecdf plot, adjust spacing in legend items

Seaborn ecdf plot, adjust spacing in legend items Question: In a Seaborn scatter plot, I can adjust the spacing in the legend entries like so: tips = sns.load_dataset(‘tips’) g = sns.scatterplot(data=tips, x="total_bill", y="tip", hue="time") plt.legend(labelspacing=20) How can I do this with a CDF plot? Running g = sns.ecdfplot(data=tips, x="total_bill", hue="time") gives a plot with the …

Total answers: 1

Arguments of bbox_to_anchor() function

Arguments of bbox_to_anchor() function Question: import matplotlib.pyplot as plt import numpy as np x = np.arange(10) fig = plt.figure() ax = plt.subplot(111) for i in xrange(5): ax.plot(x, i * x, label=’$y = %ix$’ % i) ax.legend(bbox_to_anchor=(1.1, 1.05)) plt.show() In the above code I have come accross the function bbox_to_anchor which places the legend in arbitary …

Total answers: 2

Matplotlib automatic legend outside plot

Matplotlib automatic legend outside plot Question: I am trying to use the keyword bbox_to_anchor() in a matplotlib plot in Python. Here is a very basic plot that I have produced based on this example. : import matplotlib.pyplot as plt x = [1,2,3] plt.subplot(211) plt.plot(x, label=”test1″) plt.plot([3,2,1], label=”test2″) plt.legend(bbox_to_anchor=(0, -0.15, 1, 0), loc=2, ncol=2, mode=”expand”, borderaxespad=0) …

Total answers: 2

Is it possible to add a string as a legend item in matplotlib

Is it possible to add a string as a legend item in matplotlib Question: I am producing some plots in matplotlib and would like to add explanatory text for some of the data. I want to have a string inside my legend as a separate legend item above the ‘0-10’ item. Does anyone know if …

Total answers: 3