0

I am very new to Python and I am having difficulties plotting a graph from a python code I wrote to an Excel Spreadsheet. The graph(s) are quite cluttered when using plt.show and I can't zoom in or manipulate the graph visually to see the plotted data clearly.

I've done some research on how to do it but so far, I've only managed to save the data onto a PNG File or an Excel File which saves the data as only a picture.

This is an example of the cluttered data, in the PNG Format:

Without cluttering the post with the entire code, here are the relevant bits to give some more detail:

from __future__ import division
import openpyxl as opxl
import numpy as np
import matplotlib.pyplot as plt

np.set_printoptions(threshold=np.nan)
import numpy as np

#Graphs
length1 = np.linspace(0,len(DI_plus),len(DI_plus))
length2 = np.linspace(0,len(DI_minus),len(DI_minus))
length3 = np.linspace(0,len(ADX),len(ADX))
length4 = np.linspace(0,len(ADXR),len(ADXR))

plt.figure(1)
plt.plot(length1   , DI_plus , label = 'DI_plus')
plt.plot(length2   , DI_minus, label = 'DI_minus')
plt.plot(length3+13, ADX     , label = 'ADX')
plt.plot(length4+27, ADXR    , label = 'ADXR')
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", 
borderaxespad=0.)
plt.ylabel('DMI Indicator Values')
plt.xlabel('Time period')
plt.show
plt.savefig('Workbook1.png')

plt.figure(2)    
plt.plot(close[0:])
plt.show

This is my first post so please let me know if there is any more detail I can provide to help with my request. I tried finding my issue beforehand and I found this but I can't quite make it work.

Thank you very much!

AlibekM
  • 1
  • 3
  • You can save your file as PDF. PDF is a vector format, you can zoom in into (and out of) your image. – DYZ Jul 30 '17 at 00:21
  • @DYZ Sorry I phrased myself poorly. Saving as a PDF gives the same problem as the data is still clustered, where as in Excel I could stretch the graph horizontally to accommodate the large array of data – AlibekM Jul 30 '17 at 01:00
  • Do you mean _cluttered_? – DYZ Jul 30 '17 at 01:30
  • @DYZ Sorry, yes I meant that the data is so cluttered that it is hard to see the data points. – AlibekM Jul 30 '17 at 10:12

1 Answers1

0

Use the interactive figure window that pops up after plt.show. In the top toolbar there is a button to activate the zoom function. This lets you zoom in on a part of the plot without blowing up the line thickness.

enter image description here

Xukrao
  • 8,003
  • 5
  • 26
  • 52