Issue
My Line graph dosen't stretch to the end of the border but instead starts delayed and ends before the terminating grid line. I have researched this problem but haven't gotten an answer. The following is the code for my chart:
plt.style.use("custom_style.mplstyle")
fig = plt.figure(figsize=(16, 9), dpi=240)
ax = fig.add_subplot(1, 7, (1, 6))
table = fig.add_subplot(1, 7, 7)
# Delete the grid lines from the table column
table = plt.gca()
table.get_xaxis().set_visible(False)
table.get_yaxis().set_visible(False)
plt.box(on=None)
# Create and scale table
CellColor = []
[CellColor.append(["#FFFFFF07"]) for row in range(stats.shape[0])]
theTable = table.table(cellText=stats.values, cellColours=CellColor, loc="center", cellLoc="left")
theTable.scale(1.4, 6)
theTable.set_fontsize(20)
color = "#52cc00" if float(dif) >= 0 else "#cc5240"
ax.plot_date(df["time"], df["close"], fmt=color, xdate=False, marker=None, linewidth=3, linestyle="-")
dateFMT = mdates.DateFormatter(r'%I%p')
ax.xaxis.set_major_formatter(dateFMT)
chart_name = name if isinstance(chart_name, pd.core.series.Series) else chart_name
ax.set_title(f"{chart_name}: {close} [{dif}%]", loc="left")
plt.savefig(f"charts/{name}.png")
where the contents of custom_style.mplstyle are
### FONT
text.color : white
font.family : Tahoma
### AXES
axes.facecolor : FFFFFF07 # axes background color
axes.edgecolor : FFFFFF3D # axes edge color
axes.labelcolor : FFFFFFD9
### TICKS
xtick.color : FFFFFFD9 # color of the tick labels
ytick.color : FFFFFFD9 # color of the tick labels
### GRIDS
grid.color : E6E6FA # grid color
axes.grid : True
grid.linewidth : 0.4
### Legend
legend.facecolor : inherit # legend background color (when 'inherit' uses axes.facecolor)
legend.edgecolor : FFFFFFD9 # legend edge color (when 'inherit' uses axes.edgecolor)
### FIGURE
#TODO: notebook ignores this
figure.facecolor : 0C1C23 # figure facecolor
savefig.facecolor : 0C1C23 # figure facecolor
axes.titlepad : 12
### Title
axes.titlesize : 25
axes.titlelocation : left
Solution
All you need to do is set the x
margins to 0
with plt.margins(x=0)
:
L1 = [1,2,3,4,5,6]
plt.plot(L1) # Default margins
plt.show()
plt.plot(L1)
plt.margins(x=0) # 0 Margins
plt.show()
Answered By - Michael S.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.